2012-11-20 02:34 PM
Hello,
I looking for some example code for communication between my ST-DISCOVERY F0 board and PC (UART). Can someone help me with it? I´m novice.Thank you2013-06-11 05:05 PM
Yes, you'll want to use a ring/fifo buffer, and service that with an RXNE interrupt. You'll want to turn off the interrupt when there is not additional data to send.
2013-06-19 10:44 AM
I am receiving and error while calling sscanf on the 'line_buffer' variable.
main.c(168): error: #167: argument of type ''volatile char *'' is incompatible with parameter of type ''const char *restrict'' My code within the while loop; __WFI(); // Wait for an interrupt rather than grind endlessly if (line_valid) // A new line has arrived { // ProcessLine(line_buffer); // Do something with the line char str[20]; int num; sscanf(line_buffer, ''%s %d'', str, &num); ...................... What do you think is the error here?2013-06-19 02:27 PM
What do you think is the error here?
Sounds like a casting issue. The buffer can be changed by an interrupt, and is thus transient. You can apply a cast, or copy it someplace else. A more complex implementation would require multiple buffers, and enqueuing them2013-06-19 08:09 PM
Thanks!
2013-09-17 01:33 PM
In order to tx interrupt I wrote this function, which is placing characters from printf to FIFO buffer. It is calling fromfputc(int ch, FILE *f) function and works fine.
void
FIFO_PUT(
char
ch)
{
if
(COUNT < FIFO_SIZE)
{
FIFO[COUNT] = ch;
COUNT ++;
}
}
The next function I wrote is this one. It should be sending a characters from FIFO buffer to USART. It is calling from interrupt handler.
void
FIFO_GET(
void
)
{
char
j;
char
ch;
for
(j=0;j<10; j++)
{
ch = FIFO[j];
USART_SendData(USART1, ch);
ch = 0;
}
}
In result, program is don't working. Characters from printf are correct placing to the FIFO but to USART is don't sending this characters.
Any idea?
2013-09-17 02:16 PM
Any idea?
USART_SendData() can only be used once per TXE interrupt, there's basically a single holding register so you can't stuff multiple bytes in there.2013-10-06 02:24 PM
Ok, so I replace this piece of code in interrupt handler with one from USART interrupt example for STM32F.. But it still don´t send any data to serial terminal.
if (USART_GetITStatus(USART
1
, USART_IT_TXE) != RESET)
{
USART_SendData(USART
1
, FIFO[tx_index++]);
if(tx_index == FIFO_SIZE)
{
/* Disable the USARTx Transmit interrupt */
USART_ITConfig(USART
1
, USART_IT_TXE, DISABLE);
}
}
2013-10-15 10:05 AM
Thanks Ivan and Clive1. Your discussion helped me a lot to make a project running with Uart in interrupt mode with I/O buffers.
I think the only thing missing to Ivan to get his application running (perhaps it's running today), was to manage the stop and go of the TXE interrupt (thrown when the TX buffer is empty). In the TXE interrupt when the buffer is empty, I have disable the TXE interrupt as soon as the transmit buffer is empty (in the interrupt routine). Then, as soon as a new char arrives in the buffer (fputc), I enable again the interrupt if it is in disable mode. It's working fine... Thanks again to both of you for you pieces of code. Bruno.2014-02-11 07:16 AM
With this code:
if (USART_GetITStatus(USART1, USART_IT_TXE) != RESET) // Transmit the string in a loop
{
USART_SendData(USART1, StringLoop[tx_index++]);
if (tx_index >= (sizeof(StringLoop) - 1))
tx_index = 0;
}
The UART interrupt keeps triggering endlessly unless I do something like else { disable interrupt}. Is there a better way to get it to stop triggering?
2014-02-11 07:16 AM
With this code:
if (USART_GetITStatus(USART1, USART_IT_TXE) != RESET) // Transmit the string in a loop
{
USART_SendData(USART1, StringLoop[tx_index++]);
if (tx_index >= (sizeof(StringLoop) - 1))
tx_index = 0;
}
The UART interrupt keeps triggering endlessly unless I do something like else { disable interrupt}. Is there a better way to get it to stop triggering?