Hi,
I am using TWR-K65F180M and IAR embedded workbench for ARM. I am trying to enable RX/TX interrupt in UART2 pins.For this the following changes were made
#ifndef BSP_DEFAULT_IO_CHANNEL
#if BSPCFG_ENABLE_ITTYC
#define BSP_DEFAULT_IO_CHANNEL "ittyc:" /* OpenSDA-COM polled mode */
#define BSP_DEFAULT_IO_CHANNEL_DEFINED
while(1) {
if(fstatus(uart)) {
data= fgetc(uart);
}
}
I am having certain doubts regarding the working of the code,
Please do suggest the corrections that needs to be done in the code
Original Attachment has been moved to: uart_interrupt_1.c.zip
Solved! Go to Solution.
Hi Annamol,
Quick reply with more tomorrow.
Please note the low power example has ability to wake system up using UART so please review the application and associated PDF:
Never call printf() from an isr. You never want to call functions that might block and/or take a long time to execute. This is why in my code example I was grabbing the UART data and storing it off into data[] buffer so I could halt application after having sent a bunch of characters to review in variable window and never tried to add code to the isr. Although you can set event masks and post semiphore or mutex but not wait on them.
To read on this topic look at:
C:\Freescale\Freescale_MQX_4_2\doc\mqx\MQX_User_Guide.pdf
2.23 Interrupt and Exception Handling
3.9 Handling Interrupts and Exceptions
3.9.3.1 Functions That the ISR Cannot Call
Regards,
David
Hi Annamol,
If you have the UART setup as interrupt, you should not need the IO_SERIAL_NON_BLOCKING defined as interrupt mode is inherently non-blocking.
As characters are received (or transmitted) the UART isr will add them to the UART Rx queue (or UART Tx queue for transmitted characters).
The queue size is set in the BSP board definition file (ex: twrk70f120m.h header) as #define BSPCFG_SCI0_QUEUE_SIZE 64.
You can increase or decrease this as needed.
The fstatus() function call is simply checking to see if the respective queue has any characters in it. If yes then it returns TRUE else FALSE.
I did a quick test using the hello_world MQX4.2 example for TWR-K70F120M (didn't have TWR-K65F180M handy) and was able to send long string of characters (256 long) and received correctly to application buffer (char data[512]) . Here is my code snippet and I have attached my hello.c file.
void hello_task
(
uint32_t initial_data
)
{
(void)initial_data; /* disable 'unused variable' warning */
printf("Hello World\n");
#if 1 //DES 1=test, 0=default code
char data[512];
char *data_ptr = data;
while(1) {
if(fstatus(stdin)) {
*data_ptr = fgetc(stdin);
data_ptr++;
// data= fgetc(stdin);
// fputc(data,stdout);
// fputc('\n', stdout);
}
}
#endif
_task_block();
}
Reference: C:\Freescale\Freescale_MQX_4_2\mqx\examples\hello
Regards,
David
Hi,
Thanks for the reply.
I am using UART for communicating with a BLE module. The end application has power limitations, because of which I want the device to wake up on UART interrupt (if it is in LLS) and process the data received. Whenever data comes through UART lines, I should be able to parse the data.I am still having doubts..Can you please clarify these for me...
Hi Annamol,
Quick reply with more tomorrow.
Please note the low power example has ability to wake system up using UART so please review the application and associated PDF:
Never call printf() from an isr. You never want to call functions that might block and/or take a long time to execute. This is why in my code example I was grabbing the UART data and storing it off into data[] buffer so I could halt application after having sent a bunch of characters to review in variable window and never tried to add code to the isr. Although you can set event masks and post semiphore or mutex but not wait on them.
To read on this topic look at:
C:\Freescale\Freescale_MQX_4_2\doc\mqx\MQX_User_Guide.pdf
2.23 Interrupt and Exception Handling
3.9 Handling Interrupts and Exceptions
3.9.3.1 Functions That the ISR Cannot Call
Regards,
David
Hi,
Thanks for the support. got it working with events and storing it onto buffer and using it for later processing :smileyhappy:
Hi,
One more doubt is there regarding fgetc() and data= sci_ptr->D.
What does these statements do?