UART driver receive callback

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

UART driver receive callback

Post by DeusExMachina »

Hello!
I use UARTD1 (chibios 2.4.3) with RS485(soft RTS).
I have the problem: I don't receive rx callbacks.
TX callbacks work OK. stm32F100


Code: Select all

/*
 * This callback is invoked when a transmission buffer has been completely
 * read by the driver.
 */
static void txend1(UARTDriver *uartp)
{

   (void)uartp;
   palTogglePad(GPIOA, PA_RS485_LED);
}

/*
 * This callback is invoked when a transmission has physically completed.
 */
static void txend2(UARTDriver *uartp)
{
   (void)uartp;
   palSetPad(GPIOA, PA_RS485_LED);

}

static void rxerr(UARTDriver *uartp, uartflags_t e) {

   (void)uartp;
   (void)e;
}

static void rxchar(UARTDriver *uartp, uint16_t c)
{

   (void)uartp;
   (void)c;
   /* Flashing the LED each time a character is received.*/
   palTogglePad(GPIOA, PA_RS485_LED);
}

static void rxend(UARTDriver *uartp)
{
   (void)uartp;

}

UARTConfig uart_cfg_1 = {
      txend1,                    /* End of Transmission buffer callback               */
      txend2,                    /* Physical end of transmission callback             */
      rxend,                      /* Receive buffer filled callback                    */
      rxchar,                      /* Char received while out of the UART_RECEIVE state */
      rxerr,                    /* Receive error callback                            */
      19200,                  /* Baudrate                                          */
      USART_CR1_RXNEIE,         /* cr1 register values                               */
      0,         /* cr2 register values                               */
      0                        /* cr3 register values                               */
};


int main(void)
{




   halInit();

   chSysInit();

   /*
    * Activates the uart driver 1
    */
   uartStart(&UARTD1, &uart_cfg_1);

   while (TRUE)
   {
      palSetPad(GPIOA, PA_RS485_RTS);
      chThdSleepMilliseconds(20);
      uartStartSend(&UARTD1, 14, "Hello world!\n\r"); // output works fine <<<<<<<<<<<<<<<<<<<<<<<-
      chThdSleepMilliseconds(20);
      palClearPad(GPIOA, PA_RS485_RTS);
      chThdSleepMilliseconds(20);
      uartStartReceive(&UARTD1, BUF_SZ, uart1_data.buffer); // nothing happens, callbacks dont work, when pressing smth in terminal
   }
}


User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: UART driver receive callback

Post by Giovanni »

Hi,

The callback should be triggered only when the buffer has been filled entirely, is this the behavior you expect? if so I will give it a try ASAP.

Giovanni
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: UART driver receive callback

Post by DeusExMachina »

I need a callback after receiving each char. I should use 1 element rx buffer?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: UART driver receive callback

Post by Giovanni »

Hi,

There is no need, if you don't start any receive operation you will get one callback for each receiver char, look at the example application under ./testhal.

Giovanni
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: UART driver receive callback

Post by DeusExMachina »

Thank you! I'll try :)
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: UART driver receive callback

Post by DeusExMachina »

Everything works OK, thank you
Post Reply