4 posts / 0 new
Last post
bensalemsaif
Offline
Last seen:3 years 8 months ago
加入:2016-02-02 12:42
UART2 Rx interrupt

Hello MT_dialog,

Is it possible to get an UART2 interrupt for a specified number of bytes received on Rx ?

Until now I'm calling the uart2_read(..) with a callback function to retrieve a bye but I'm doing it in a loop and I want it to be automatically done by interrupt , so my callback function gets called if a specified number of bytes arrives. is it possible ?

Thank you,
-- Saif

Device:
MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
加入:2015-06-08 11:34
Hi bensalemsaif,

Hi bensalemsaif,

You can change the FIFO level and set it to trigger an interrupt when the FIFO reaches a specific level. For example if you set the UART2_IIR_FCR_REG register to the value of 0x87 this will trigger a RECEIVE_AVAILABLE interrupt every 1/2 full of the 16 byte FIFO (receive interrupt every 8 bytes). There are a few other options for this 1/4 FIFO full and 2 less that FIFO full, the setting of 0 is one character in the FIFO.

Thanks MT_dialog

bensalemsaif
Offline
Last seen:3 years 8 months ago
加入:2016-02-02 12:42
Hello MT_dialog,

Hello MT_dialog,

I changed this line in uart2.c :
SetWord16(UART2_IIR_FCR_REG,7); --> SetWord16(UART2_IIR_FCR_REG,0); but I still not get anything in UART2_Handler , here is my uart2_init function :

+++++++++++++++++++++++++++++++
//ENABLE FIFO, REGISTER FCR IF UART2_LCR_REG.DLAB=0
// XMIT FIFO RESET, RCVR FIFO RESET, FIFO ENABLED
SetBits16(UART2_LCR_REG, UART_DLAB, 0);
SetWord16(UART2_IIR_FCR_REG,0);

//DISABLE INTERRUPTS, REGISTER IER IF UART2_LCR_REG.DLAB=0
SetWord16 (UART2_IER_DLH_REG 0);

// ACCESS DIVISORLATCH REGISTER FOR BAUDRATE 115200, REGISTER UART_DLH/DLL_REG IF UART2_LCR_REG.DLAB=1
SetBits16(UART2_LCR_REG, UART_DLAB, 1);
SetWord16(UART2_IER_DLH_REG,0); // for serial clk 16MHz baudrate 115200
SetWord16(UART2_IER_DLH_REG, (baudr&0xFF>>0x8));
SetWord16(UART2_RBR_THR_DLL_REG,baudr&0xFF); // set baudrate ~115200 = serial_clk/(16*9)

// NO PARITY, 1 STOP BIT, 8 DATA LENGTH AND
SetWord16(UART2_LCR_REG,mode);

//ENABLE TX INTERRUPTS, REGISTER IER IF UART2_LCR_REG.DLAB=0
SetBits16(UART2_LCR_REG, UART_DLAB, 0);

NVIC_DisableIRQ(UART2_IRQn);
NVIC_SetPriority(UART2_IRQn,1);
NVIC_EnableIRQ(UART2_IRQn);
NVIC_ClearPendingIRQ(UART2_IRQn);

// Configure UART environment
uart2_env.errordetect = UART_ERROR_DETECT_DISABLED;
uart2_env.rx.bufptr = NULL;
uart2_env.rx.size = 0;
uart2_env.tx.bufptr = NULL;
uart2_env.tx.size = 0;
++++++++++++++++++++++++++++++++++

Is there anything missing ? the only way to get data on uart2 is to call the uart2_read function , but I want to get an interrupt.

Thanks,
-- Saif

MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
加入:2015-06-08 11:34
Hi bensalemsaif,

Hi bensalemsaif,

You can take the peripheral_examples project and the uart2_async as an example, the uart2_read() function is invoked in order to set the enviroment for the uart, the function uart2_rec_data_avail_setf() is the function that enables the receive available interrupt. Since the interrupts are enabled after each available character an interrut is triggered in the UART2_Handler() (you can place a break point and check). When you invoke the uart2_read() as parameters you place a buffer for your data, how many data you wait to receive and what is the callback that will trigger when those data are received, and then the receive interrupts are enabled. So with the interrupts enabled every time you get a character theUART2_Handler() will hit and with aRECEIVED_AVAILABLE idd and the uart2_rec_data_avail_isr() will be executed. The uart2_rec_data_avail_isr() will place that data from the UART in the buffer of the enviroment and reduce the count of the enviroment's expected character. When the all the expected characters arrive the uart2_rec_data_avail_isr() will disable the receive interrupts, place a null variable in the uart enviroment callback and then execute the callback itself. In the above implementation you dont invoke theuart2_rec_data_avail_setf() in order to enable the receive interrupt.

Thanks MT_dialog