UART2_Handler can't get triggered?

6 posts / 0 new
Last post
chris0409
Offline
Last seen:3年10 months ago
加入:2017-01-11 05:59
UART2_Handler can't get triggered?

HI, Dialog Engineers,
I have done some modification on ble_peripheral sample project, and I can send data using arch_printf() through uart2, but I can't get any Rx interrupt because the UART2_Handler never be invoked, I have compare the UART2_init() with that in project uart2_async project, and they are the same code, does anybody have an idea? any of your suggestion would be much appreciated

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

Hi chris0409,

In order to get an interrupt when you have available data you need to enable the interrupt in the UART module of the UART2_IER_DLH_REG, the uart2_async project when the program read and it enables that interrupt by invoking the uart2_read() function (the interrupt on received data is set in the uart2_rec_data_avail_setf(1); function). Have you invoked that function in order to get the received Data available interrupt ?

Thanks MT_dialog

chris0409
Offline
Last seen:3年10 months ago
加入:2017-01-11 05:59
Hi, MT_dialog,

Hi, MT_dialog,
I invoke the uart2_read after the uart_init, but I still can't get the UART2_Handler() triggered? and if I send a string from uart terminal, and I can just get UART2_Handler() one time.
the code is like this

static uint8_t buffer[2] =0;
void periph_init(void)
{

// Power up peripherals' power domain
SetBits16(PMU_CTRL_REG, PERIPH_SLEEP, 0);
while (!(GetWord16(SYS_STAT_REG) & PER_IS_UP));

SetBits16(CLK_16M_REG, XTAL16_BIAS_SH_ENABLE, 1);
//rom patch
patch_func();
//Init pads
set_pad_functions();
#ifdef CFG_PRINTF_UART2
SetBits16(CLK_PER_REG, UART2_ENABLE, 1);
uart2_init(UART_BAUDRATE_115K2, 3);
#endif
uart2_read(&buffer, 1, NULL);
/ /启用垫
SetBits16(SYS_CTRL_REG, PAD_LATCH_EN, 1);

Is there anything else I should add? I need to capture every byte from uart at anytime, so I can't use it in a while loop.any suggestion?

MT_dialog
Offline
Last seen:2 months 2 weeks ago
Staff
加入:2015-06-08 11:34
嗨Chris0409,

嗨Chris0409,

There is no additional configuration in order to get a received interrupt from the UART, the code that you ve pasted works as it should be on my side and i get the receive interrupt on the UART2_Handler() for every character i send, if you dont get this then i suppose that you are operating under sleep mode, that means that you wont be able to get the interrupt that you would like since the UART module is switched off when the device is sleeping (you should still be able to get the interrupt but only if the sending of the character occurs at the same time the BLE is awaken in order to advertise or keep a connection alive). If you switch to no sleep mode or keep the device awake when you are expecting data then this should work.

Thanks MT_dialog

chris0409
Offline
Last seen:3年10 months ago
加入:2017-01-11 05:59
Hi, MT_Dialog,

Hi, MT_Dialog,
The ble_peripheral sample project use a sleep mode of ARCH_SLEEP_OFF , so it will doesn't sleep,now I use the uart2_read() in the main_func() , and it works fine.

MT_dialog
Offline
Last seen:2 months 2 weeks ago
Staff
加入:2015-06-08 11:34
Hi chris0409,

Hi chris0409,

Glad this fits you, but in order to give you some more insight on this, when you invoke the read2_read with the parameter of size as 1, you are only going to get 1 interrupt, since this is the size that you have declared (missed the point that you mentioned that you get only one interrupt, i was under the impression that you couldn't get any interrupt as mentioned in your first port). So after the receive interrupt is available the uart2_rec_data_avail_isr() reduces the amount of size that you have declared and eventually when no other data are expected since the size is zero, the function disables that interrupt. Now what you can do is to declare a callback function to whatever size that you would like (the uart2_read() function takes a third parameter as a callback that will be called when the size of the the received data reaches the value that the user declared) and have this callback reset your interrupt (invoke the uart2_read() from within that callback) with the same or any kind of size that you would like.

Thanks MT_dialog