реклама на сайте
подробности

 
 
> USART stm32f2xx по новой ...StdPeriph_Driver
Acvarif
сообщение Dec 26 2011, 06:52
Сообщение #1


Знающий
****

Группа: Участник
Сообщений: 998
Регистрация: 27-08-08
Пользователь №: 39 850



Пытаюсь запустить передачу по USART используя последнюю версию библиотеки STM32F2xx_StdPeriph_Driver
Все делаю по инструкции. Но USART ничего не передает. Может кто, кому не лень, зметит неточность в инициализации.
Код построил на базе scmRTOS310

Инициализация:
CODE
// 1.
// Enable peripheral clock using the follwoing functions
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_USARTx, ENABLE) for USART1 and USART6
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_USARTx, ENABLE) for USART2, USART3, UART4 or UART5.

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

// 3.
// According to the USART mode, enable the GPIO clocks using
// RCC_AHB1PeriphClockCmd() function. (The I/O can be TX, RX, CTS,
// or/and SCLK).

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

// 3.
// Peripheral's alternate function:
// - Connect the pin to the desired peripherals' Alternate
// Function (AF) using GPIO_PinAFConfig() function
// - Configure the desired pin in alternate function by:
// GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
// - Select the type, pull-up/pull-down and output speed via
// GPIO_PuPd, GPIO_OType and GPIO_Speed members
// - Call GPIO_Init() function

GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART1);

// USART1 Rx
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// USART1 Tx
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

// 4.
// Program the Baud Rate, Word Length , Stop Bit, Parity, Hardware
// flow control and Mode(Receiver/Transmitter) using the USART_Init()
// function.

/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/

USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);

// 5.
// For synchronous mode, enable the clock and program the polarity,
// phase and last bit using the USART_ClockInit() function.

// 6.
// Enable the NVIC and the corresponding interrupt using the function
// USART_ITConfig() if you need to use interrupt mode.

// 7.
// When using the DMA mode
// - Configure the DMA using DMA_Init() function
// - Active the needed channel Request using USART_DMACmd() function

// 8.
// Enable the USART using the USART_Cmd() function.

USART_Cmd(USART1, ENABLE);

// 9.
// Enable the DMA using the DMA_Cmd() function, when using DMA mode.


Далее по переполнению системного таймера (~5мс):

Код
    
template<> OS_PROCESS void TProc2::Exec()
{
for(;;)
    {
      Timer_B_Ovf.Wait();

      GPIO_SetBits(GPIOB, GPIO_Pin_9);
      Delay(0x0000FF);
      GPIO_ResetBits(GPIOB, GPIO_Pin_9);
      Delay(0x0000FF);

      USART_SendData(USART1, 0x55);

     }
}

Переполнение системного таймера контролируется по GPIO_Pin_9 порта В (все работает)

Сообщение отредактировал IgorKossak - Dec 26 2011, 08:48
Причина редактирования: [codebox]
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов
shmur
сообщение Dec 26 2011, 07:04
Сообщение #2


Участник
*

Группа: Участник
Сообщений: 55
Регистрация: 28-11-11
Пользователь №: 68 553



GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART1);

Наверное должен быть GPIOA.
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 19th July 2025 - 21:47
Рейтинг@Mail.ru


Страница сгенерированна за 0.01368 секунд с 7
ELECTRONIX ©2004-2016