Пытаюсь запустить передачу по 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]