cancel
Showing results for 
Search instead for 
Did you mean: 

generate callback function

Pilous Droip
Senior
Posted on March 10, 2018 at 17:27

Hello friends.

I have uart. And I need generate callback function.

For example. I send from PC 0x01 and I need generate call back function 'HelloWorld'. Send 0x02 generate 'SunShine'.

So I receive char in interrupt:

void UART4_IRQHandler(void)

{

   if (LL_USART_IsActiveFlag_RTO(UART4))

   {

      LL_USART_ClearFlag_RTO(UART4); 

      UART_generate_call_back(dma_rx_buff);

      

/* here clear flags, .........*/

   }

}

/* here is my definitions */

&sharpdefine    FIRST_CALL         0x01

&sharpdefine    SECOND_CALL    0x02

function generate call back:

void UART_generate_call_back(uint8_t *input_buffer)

{

   if(

input_buffer

[0] == 0x01)

      UART_HandlerTable(FIRST_CALL);

   if(

input_buffer

[0] == 0x02)

      UART_HandlerTable(SECOND_CALL);

}

and my function to generate callback:

void UART_callback(uint32_t InterruptID, InterruptHandler Handler)

{

   UART_HandlerTable = Handler;

}

other function and declaration:

typedef void (*InterruptHandler) (uint32_t uart_interrupt);

InterruptHandler UART_HandlerTable;

And in my main:

void HelloWorld();

void SunShine();

int main(void)

{

   /* init system clock */

   SystemClock_Config();

   /* Init UART5 and DMA1 */

   MX_UART4_Init();

   /* Init LED */

   InitLed();

   UART_callback(

FIRST_CALL

, (InterruptHandler)

HelloWorld

);

   UART_callback( SECOND

_CALL

, (InterruptHandler)

SunShine

);

   while (1)

   {

      LL_mDelay(1);

      time++;

      if(time == 500)

      {

         LL_GPIO_TogglePin(MCU_LED_PORT, MCU_LED_PIN);

         time = 0;

      }

}

void HelloWorld()

{

   usart_puts('Hello world\r\n');

}

void SunShine()

{

   usart_puts('Sunshine\r\n');

}

And when I send 0x01 by UART callback function isn't working.

Any idea, what is wrong?

#callback #nucleo-f767zi
2 REPLIES 2
Posted on March 10, 2018 at 17:45

Does UART_callback() do anything with InterruptID ?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 10, 2018 at 18:02

Yes, it true. 

🙂

InterruptHandler UART_HandlerTable[MAX_INTERRUPT];

void UART_callback(uint32_t InterruptID, InterruptHandler Handler)

{

   UART_HandlerTable[InterruptID] = Handler;

}

void UART_generate_call_back(uint8_t *input_buffer)

{

   if(input_buffer[0] == 0x01)

      UART_HandlerTable[

FIRST_CALL

](FIRST_CALL);

   if(input_buffer[0] == 0x02)

      UART_HandlerTable[

SECOND_CALL

](SECOND_CALL);

}

Now it is working.

It was my mistake. 

🙂