cancel
Showing results for 
Search instead for 
Did you mean: 

UART PRBLEM with STM32F3

hilwan
Associate II
Posted on January 30, 2014 at 10:51

The original post was too long to process during our migration. Please click on the attachment to read the original post.
21 REPLIES 21
Posted on January 30, 2014 at 20:08

You IRQHandler is weird

You spin on RXNE when you should just test it, that's why it entered.

You spin on TXE *AFTER* sending data, if you absolutely must spin, do it BEFORE, otherwise you might dwell for over a character time.

Check the framing error in status register, if you get it a lot scope the data to understand why there is an issue with the timing, and why this might be occurring. Check that your clocks are correct.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hilwan
Associate II
Posted on January 30, 2014 at 22:49

Thanks clive1.

IRQHandler is weird : sorry i don't understand why, do you have an other idea to this stuff ?

Normally, in the reception part, the interruption is occurred to read received data, then i want to test the emission part, this way i send a character to my PC

hilwan
Associate II
Posted on January 30, 2014 at 22:53

Thanks clive1.

IRQHandler is weird : sorry i don't understand why, do you have an other idea to this stuff ?

Normally, in the reception part, the interruption is occurred to read received data, then i want to test the emission part, this way i send a character to my PC

Posted on January 30, 2014 at 23:05

I though I described why. Generally you want to avoid while() loops in interrupts, especially when you might get stuck there for extended periods, or forever.

void USART1_IRQHandler(void)
{
if (USART_GetITStatus(USART1, USART_IT_RXNE))
{
/* Read one byte from the receive data register */
rx_buffer[rx_counter] = USART_ReceiveData(USART1) & 0x7F;
/* Loop until transmit data register is empty, spin if we must */
while(!(USART1->ISR & USART_FLAG_TXE));
/* Put character on the serial line */
USART1->TDR = 25; // '%'
if (((rx_counter + 1) >= RX_BUFFER_LENGTH) ||
(rx_buffer[rx_counter] == '
') ||
(rx_buffer[rx_counter] == '
'))
{ 
rx_counter = 0;
}
else
{
rx_counter++;
STM_EVAL_LEDToggle(LED4);
}
}
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hilwan
Associate II
Posted on January 31, 2014 at 17:53

I've tried your modification but still have the same problems, the 

USART1_IRQHandler

is executed even if no data is sent and when i send something, i can receive and send but the wrong data. An other thing is that the ''FE'' is always set.

I can't really see what would be the problem.

Thanks for your help 

Posted on January 31, 2014 at 18:14

What  USB UART are you using? The pins of the STM32 are NOT RS232 level compatible.

Have you tried sending a stream of characters ('U') from the STM32 and observed the signal on the TX pin? Use a scope, verify the bit timing.

Have you tried looping the TX and RX pins of the STM32 and determined you can send/receive data correctly there?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hilwan
Associate II
Posted on January 31, 2014 at 18:31

1) USB To serial type device FTDI (made in china !! )

2) not yet, i ll do it

3) not yet, i ll do it 

Thanks for this remarks 

hilwan
Associate II
Posted on February 02, 2014 at 22:35

Have you tried looping the TX and RX pins of the STM32 and determined you can send/receive data correctly there? : I have tried this but doesn't work, i really don't know what going with my code. An other thing the RDR and TDR contains the value sent and received but the bit RXNE never set.

My main is below :

int main(void)

{

 /* Initialize USART communication */

     USART1_Init2(9600);

     while(!(USART1->ISR & USART_FLAG_TXE));

     /* Put character on the serial line */

      USART1->TDR = 25; // '%'

        STM_EVAL_LEDOn(LED5);

         if ((USART1->ISR & USART_FLAG_RXNE))

     {

    /* Read one byte from the receive data register */

       rx= USART_ReceiveData(USART1) & 0x7F;

           STM_EVAL_LEDOff(LED5);

       }

    while(1){};

}

Posted on February 03, 2014 at 01:36

Are you sure PB6/PB7 are appropriate for the STM32F3-DISCO, don't they clash with the I2C of the LSM device?

Why can't you use PA9/PA10 which are actually free?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..