cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to send data via UART Serial Link

skillet
Associate II
Posted on February 07, 2013 at 05:12

I am trying to send data to a PC COM port but cannot figure it out

I configured GPIO, NVIC, and USART per specification and it all checks out. The strange thing is, when I connect the Tx pin and ground to oscilloscope, it shows that it is sending out data. However, on the other end, terminal software is not receiving any data.

Any idea what is wrong?

#gpio #nvic #uart #serial
7 REPLIES 7
Posted on February 07, 2013 at 05:18

Is the bit time correct? Are the signals electrically compatible?

Find a working board/example, and compare/contrast with your circuit/software.

Show your code, diagram your circuit, guessing is overrated.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
skillet
Associate II
Posted on February 07, 2013 at 07:46

I am using this to configure serial communication and transmit data.

void SERIAL_Config(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

USART_InitTypeDef USART_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOA, &GPIO_InitStructure);*/

/////////////////////////////////////////

GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOA, &GPIO_InitStructure);

//see stm32f4xx_usart

USART_InitStructure.USART_BaudRate = SERIAL_BAUDRATE;//460800;//921600;//230400;//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_Tx;

USART_Init(USART1, &USART_InitStructure);

USART_Cmd(USART1, ENABLE);

SERIAL_CallBack_InBufferAscii = NULL;

SERIAL_CallBack_InbufferBinary = NULL;

while(1)

{

USART_SendData(USART1, 'U');

while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);

}

}

Is there anything here which might explain why the data is not received on the PC end?

Posted on February 07, 2013 at 11:45

A broken cable, for example.

JW
mr239955_stm1
Associate II
Posted on February 07, 2013 at 13:31

Are you using a level converter. This makes sure the levels between the usart (at ttl level) is shifted to the USB level of your pc and vise versa..
Posted on February 07, 2013 at 13:32

Is there anything here which might explain why the data is not received on the PC end?

Code doesn't appear unreasonable, suggest you look at the wiring, and the signals. Use a scope.

If you don't wire the signals to the right destination. Won't Work

If you push CMOS signals to a RS232 interface. Won't Work

If you push Transmit of the source, to physical Transmit of the destination. Won't Work

If you don't have a common ground connection. Won't Work

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jj2
Associate II
Posted on February 07, 2013 at 16:41

Beyond advice/guidance given - insure that you are sending ''normal'' text - not a Control Code or non-Ascii or char w/msb set.  (i.e. 0X8X)

Update/Edit:  Upon read of your code - see that you're sending ''U'' - which is ideal for scope presentation w/alternating up/down bits.  Code shows ''SERIAL_BAUDRATE'' - cannot find that define.  Suggest that you start far slower (9600) to lessen effects of capacitance and cable limitations. 

Also - may help to add normal LF/CR - just in case your PC set-up requires proper EOL (end of line) termination to display...

PC side must be set to receive (usually) 8-N-1 - (8 data bits, No Parity, 1 Stop Bit). 

Also insure that PC has not defaulted to, ''Flow Control.''  Either HW or SW Flow Control can confound your early efforts.

Posted on February 07, 2013 at 16:57

If this is STM32F4-Discovery board there is a large capacitor on one of the USART1 pins as I recall.

https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/F4Discovery%20using%20UART1&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=1905

Again some specificity about the board and wiring may assist resolution.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..