0
votes

I have been working on a project which needs to use the UART. I have referenced many different sources and am confident that the USART is setup correctly. I have been running through the code on the debugger and I noticed that my xmitbuffer is properly filling. I am trying to print hello in a loop and as I go through the code the buffer gets filled with HelloHelloHello. This matches what is expected. However, nothing shows up on the terminal. I have tried putty as well as TeraTerm.

I looked at the status register for USART1 and the TX bit is set to 1. I assume the 1 indicates that the transmit is complete. I have tried it with baud rates of 9600 and 115200 and neither have had any success. I am not sure how to continue.

It is also import to note the cable I am using to send the USART to the PC. I am using the USB-RS232-WE-1800-BT_0.0 from FTDI (http://www.ftdichip.com/Products/Cables/USBRS232.htm) I am thinking that this could be my error. Does this cable work for this application? Do I need a TTL cable instead?

All the setup is below as well as my main function.

USART Setup:

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

USART_InitStruct.USART_BaudRate = 9600;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_Parity = USART_Parity_No ;
USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_Init(USART1, &USART_InitStruct);

USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

USART_Cmd(USART1, ENABLE);

GPIO Setup: Most of this is for other devices. Port A pins 9 and 10 are the USART TX and RX pins that we are using.

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); 
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); 
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); 

GPIO_A.GPIO_Pin  = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_15;
GPIO_A.GPIO_Mode = GPIO_Mode_IN;
GPIO_A.GPIO_Speed = GPIO_Speed_Level_2;
GPIO_A.GPIO_OType = GPIO_OType_PP;
GPIO_A.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_B.GPIO_Pin  = GPIO_Pin_All;
GPIO_B.GPIO_Mode = GPIO_Mode_IN;
GPIO_B.GPIO_Speed = GPIO_Speed_Level_2;
GPIO_B.GPIO_OType = GPIO_OType_PP;
GPIO_B.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_C.GPIO_Pin  = GPIO_Pin_All;
GPIO_C.GPIO_Mode = GPIO_Mode_IN;
GPIO_C.GPIO_Speed = GPIO_Speed_Level_2;
GPIO_C.GPIO_OType = GPIO_OType_PP;
GPIO_C.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_Init(GPIOA, &GPIO_A);
GPIO_Init(GPIOB, &GPIO_B);
GPIO_Init(GPIOC, &GPIO_C);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);

Main:

void main(void)
{
    initMicro();


    while(1)
    {

        printf("Hello");
    }

}
1

1 Answers

0
votes

If you're connecting your cable directly to your MCU, then that is your problem. Table 5.3 of the cable's datasheet indicates that it uses standard RS-232 voltage levels, and a look at the schematics in section 6 of the datasheet shows the use of an RS-232 level shifter. The supply voltage to the MCU in the STM32F0DISCOVERY board is 3V, so I/O levels are single-supply 3V, which is incompatible with the RS-232 standard.

The least headache-y solution would be to buy a new cable, and for that look around for one with 3V or 3.3V I/Os -- the extra 0.3 V shouldn't be a problem. Here's one from SparkFun, but you should easily find alternatives (possibly cheaper) on eBay or AliExpress.

The low-cost solution would be to unsolder the voltage-level shifter from your current cable, and connect the pins directly to the FTDI chip on it (FT232RQ). The problem is the 5V voltage level on the FTDI chip, so you'll need to ensure that the I/Os in the STM32 that you will connect it to are 5V-tolerant, otherwise the STM32 will let out the magic smoke. To ensure a 3.3V I/O voltage level, you could modify your cable by disconnecting pin 1 of the FT232RQ from VCC (which would involve cutting a track on the PCB) and then connect it to pin 16 of the same chip, which is a 3.3V output.