KL25/26 receive from multiple UARTs

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

KL25/26 receive from multiple UARTs

960 次查看
michaelnetshipi
Contributor I

Hi,

I am trying to connect to 2 devices on UART0 and UART1.

I get this problem when I open both UART0 and UART1:

After opening first UART: I can read/write on first UART properly.

After opening second UART: I can read/write on  second UART, but i can only write to the first UART. trying to receive from the first UART blocks and crashes the application (eventually).

However, they both work correctly when only one of them is opened.

What do i need to do to receive from both UARTs properly?

I have my clocks setup like this.

  SIM->SOPT2 &= ~SIM_SOPT2_UART0SRC_MASK;

    SIM->SOPT2 |= (uint32_t)SIM_SOPT2_UART0SRC(0x01); //0x4000000

    SIM->SOPT2 |= (uint32_t)SIM_SOPT2_PLLFLLSEL_MASK;

    SIM->CLKDIV1 &= ~SIM_CLKDIV1_OUTDIV4_MASK;

    SIM->CLKDIV1 |= SIM_CLKDIV1_OUTDIV4(0x01);  //0x10000

UART0 is setup like this: using serial_api.h from mbed.

    serial_init(&_serial0, PTA2, PTA1);  //24, 23

    serial_irq_handler(&_serial0, serial0_irq_handler, &_serial0);

    serial_irq_set(&_serial0, RxIrq, TRUE);

    serial_baud(&_serial0, 57600);

UART1 is setup like this: (also using serial_api.h from mbed).

    serial_init(&_serial1, PTC4, PTC3);  //49, 46

    serial_irq_handler(&_serial1, serial1_irq_handler, &_serial1);

    serial_irq_set(&_serial1, RxIrq, TRUE);

    serial_baud(&_serial1, 57600);

Both UARTs are using a ringbuffer for in the ISR of receive.

Kind Regards,

Michael

0 项奖励
回复
1 回复

823 次查看
michaelnetshipi
Contributor I

It turns out that calling serial_irq_handler() replaces the old handler w/ a new one.

serial_api.c

void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) {

    irq_handler = handler;

    serial_irq_ids[obj->index] = id;

}

0 项奖励
回复