Hi Guys
I'm at a point of confusion, vie set-up my STM32F103C8TC6 for USART communication im stuck with the following problem.
When I send a string of characters none of the character seem to appear at the terminal window, I can verify communication on the USART2 TX bus, the scope shows data however, the decoded ASCII OR HEX data isn't correct at all I'm totally lost.
int main(void)
{
setup_init();
uint8_t data[] = {0x55, 0x01, 0x02, 0x03, 0x04, 0x00};
while(1)
{
send_string(data);
delay();
}
}
void setup_init()
{
// Setup system clocks.
rcc_config();
// Setup GPIO
gpio_config();
usart1_config();
// Setup Printf USART2
usart2_config();
}
void rcc_config(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
/* USART-1 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* USART-2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
}
void gpio_config()
{
/* Configure USART1_TX as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; // PA.10 USART1.TX
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1_RX as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; // PA.11 USART1.RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART2 Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // PA.2 USART2.TX
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART2 Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // PA.3 USART2.RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void send_string(const char *str)
{
while (*str)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, ((uint16_t)str++) );
}
}
void usart2_config(void)
{
USART_InitTypeDef USART_InitStructure;
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 9600 baud
- Word Length = 8 Bits
- Two Stop Bit
- Odd parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 9600;
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 configuration */
USART_Init(USART2, &USART_InitStructure);
/* Enable the USART2 */
USART_Cmd(USART2, ENABLE);
}
See attachment I was expecting the data order 0x55, 0x01, 0x02, 0x03, 0x04 and 0x00 null character. However I got crap, the clock is set at 72MHZ.
I've looked at the datasheet and looked at the demo sample code and on-line resources, either im suffering from tunnel vision or something else is wrong.