IAR UART_Setcallback function problem

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

IAR UART_Setcallback function problem

ソリューションへジャンプ
1,002件の閲覧回数
davetelling
Contributor I

I have a UART function that should receive an ASCII character, put it into a small buffer, increment a buffer counter, and set a flag if a CR or LF is received. This function should occur when the KE02Z UART1 generates an RDRF as a complete character comes into the UART.

Here is the interrupt function:

void UART_Rx_Task(void)

{

  uint8_t tempData;

  /* reset RDB flag */

  tempData = UART_CheckFlag(UART1, UART_FlagRDRF);

  /* read the character and put into buffer */

  inChar[rxBufCount] = UART_ReadDataReg(UART1);

  if ((inChar[rxBufCount] == CR) || (inChar[rxBufCount] == LF))

  {

    rxFull = true;

    rxBufCount = 0;

  }

  else

  {

    rxBufCount++;

    if (rxBufCount >= rxMax)

    {

      rxBufCount = 0;

      rxFull = true;

    }

  }

}

Without going into a discussion about the best way to do this, my real problem is that I cannot seem to tell the program to uses this interrupt.

The IAR tools have a predefined function (in 'uart.h'):

void UART_SetCallback(UART_CallbackType pfnCallback);

The "CallbackType" is defined like this:

typedef void (*UART_CallbackType)(UART_Type *pUART);

I am not exactly sure what this means - C syntax is not my field of expertise, and when I try to compile this, I get this error message:

Error[Pe167]: argument of type "void (*)(void)" is incompatible with parameter of type "UART_CallbackType"

Can someone explain what exactly this means, in non-professional programmer language?

0 件の賞賛
1 解決策
778件の閲覧回数
paulstoffregen
Contributor III

The problem is how you created your function:

void UART_Rx_Task(void)

It's not acceptable to use "(void)" to define your function.  It doesn't matter if that works for other cases like FTM.  The code you're trying to use requires your function to be like this:


void UART_Rx_Task(UART_Type *pUART)

Even if you don't want the pUART variable, your function MUST be defined this way, because that other code sends a pUART variable when it calls your function.  It's illegal to try to use a function that doesn't take anything as input, because the code which already exists sends something in pUART.


That's what the compiler is trying to tell you, and I'm trying to tell you too.  Maybe you don't want to believe us?

元の投稿で解決策を見る

0 件の賞賛
4 返答(返信)
778件の閲覧回数
paulstoffregen
Contributor III

The "void (*)(void)" error means you've created a function that take no inputs, but to be compatible, it needs to take 1 input of type "UART_CallbackType".

You're not required to actually *do* anything with whatever data you get from the input parameter.  But you must accept the input parameter to get your function called, because the code which already exists to call your function passes something in that parameter.  Your function just can't be compatible if it doesn't receive the data which the calling code sends.

ps: if anyone from Freescale sees this reply.... I had to try several times to log in.  I got an unhelpful "unsuccessful" error several times, and even one "500 - Internal Server Error" from your site.  I nearly gave up.  Why bother with a troublesome website, just to answer a random tech question?

0 件の賞賛
778件の閲覧回数
davetelling
Contributor I

Paul,

I realize that I forgot some of my code!

In my main() function, I have this line:

UART_SetCallback(UART_Rx_Task);

This should reference the function I wrote previously. At least, that is how I use it for the FTMx interrupts, with no problems.

0 件の賞賛
779件の閲覧回数
paulstoffregen
Contributor III

The problem is how you created your function:

void UART_Rx_Task(void)

It's not acceptable to use "(void)" to define your function.  It doesn't matter if that works for other cases like FTM.  The code you're trying to use requires your function to be like this:


void UART_Rx_Task(UART_Type *pUART)

Even if you don't want the pUART variable, your function MUST be defined this way, because that other code sends a pUART variable when it calls your function.  It's illegal to try to use a function that doesn't take anything as input, because the code which already exists sends something in pUART.


That's what the compiler is trying to tell you, and I'm trying to tell you too.  Maybe you don't want to believe us?

0 件の賞賛
778件の閲覧回数
davetelling
Contributor I

Welll...I am not sure what to believe at this point. I have written assembler and 'C' for several microcontrollers over the years, currently the Atmel AVR series, and I have never had the problems I have encountered trying to make this ARM Cortex part work. Since I am not a programmer, but an engineer, I don't code all the time, only when I need firmware for a project, so please bear with me.

Adding "UART_Type *pUART" in the parentheses allowed the program to compile, and my isr is reached when I send a character, so I thank you very much for your help. I still do not understand why IAR has set up their examples like this, but at this point, I need to move on.

Thank you again for your help!

0 件の賞賛