MODSERIAL attach problem! Help

Hello, I use the MODSERIAL library on KL25Z is when I want to attach a function, the compiler indicates the following error message: Error: No instance of overloaded function “AjK::MODSERIAL::attach” matches the argument list in “main.cpp”, Line: 23, Col: 15

Here is the code:

#include “mbed.h”
#include “MODSERIAL.h”

#define COM_SPEED_LONG 19200
#define COM_SPEED_SHORT 19200

MODSERIAL PC_Short(PTA2,PTA1);
MODSERIAL PC_Long(PTE0,PTE1);

void test()
{
int toto;
toto +=3;
}

int main()
{//main

PC_Long.baud (COM_SPEED_LONG);
PC_Short.baud (COM_SPEED_SHORT);
      
PC_Short.attach(& test, MODSERIAL::RxIrq);

while(true)
    {//lecture           

                   
    }//lecture     

}//main

Have not tried it but there should be no space between & and test
PC_Short.attach(&test, MODSERIAL::RxIrq);

Since you are using Andy Kirkham’s MODSERIAL library the RxIrq ISR must have one argument - a pointer to MODSERIAL_IRQ_INFO (even when it isn’t used in the body of your ISR). Moreover, if your intention is to use the same variable in the ISR and also in the main function then it shall be defined as global and volatile (to make it visible at both places and to prevent the compiler from deleting it when optimizing the code):

volatile int toto = 0;  // global & volatile

...

//void test()
void test(MODSERIAL_IRQ_INFO *) {
    //int toto;
    toto += 3;
}

...

int main()
{
    ...
    PC_Short.attach(&test, MODSERIAL::RxIrq); 
    ...
    while(true) {
        ...
        if (toto != 0) {
            printf("toto = %d\r\n", toto);
        }
       ...
    }
}

Hi,

Thank you for your specific answer!
I had found this method in other post, and so with the argument * it works.

But I have another problem now!
In my interuption, I call the “move” function of MODSERIAL which allows me to retrieve a string of text via thebuffer serie.

It works the first time, but then has every interrupt call, a character and truncated!
Here is the code:

////////////////////////////////////////////////////////////
#define com_speed_short 19200

const char valid = 248;
char texte[100];

MODSERIAL PC_Short(PTE22,PTE23);

void flushSerialBufferShort(void){while (PC_Short.readable()) {PC_Short.getc();} return;}

void read_bus_serie(MODSERIAL_IRQ_INFO *) 
	{
		PC_Short.move(texte,50);
                
                //action_read_buff();//action     
                flushSerialBufferShort();               
	}

int main()
{
    PC_Short.baud(com_speed_short);//....................................................................Initialise 
    PC_Short.autoDetectChar(valid); 

    PC_Short.attach(&read_bus_serie, MODSERIAL::RxAutoDetect);

    
    flushSerialBufferShort();

    while(true) 
    {
    }
}
//////////////////////////////////////////////////////

Then I tried another method that conciseness to trigger a global varible and then authorize a

function in which I use “move” and then I empty the reception buffer.
The code:

/////////////////////////////////////////////////
#define com_speed_short 19200

const char valid = 248;
char texte[100];
volatile int sFlag;

MODSERIAL PC_Short(PTE22,PTE23);

void flushSerialBufferShort(void){while (PC_Short.readable()) {PC_Short.getc();} return;}

void read_bus_serie(MODSERIAL_IRQ_INFO *) {sFlag = 1;}

int main()
{

    PC_Short.baud(com_speed_short);//....................................................................Initialise 
    PC_Short.autoDetectChar(valid); 

    PC_Short.attach(&read_bus_serie, MODSERIAL::RxAutoDetect);

 
    flushSerialBufferShort();

    while(true) 
    {
          
        
         if(sFlag == 1)
            {                         
                PC_Short.move(texte,50);
                
                //action_read_buff();//action     
                flushSerialBufferShort();               
                sFlag = 0;
            }
    
    }
}
//////////////////////////////////////////////////////////

It works, but using an IF in the main loop and a global variable bothers me, I would prefer everything

include in the interruption as in the 1st code!
is possible?

Thank you for your answers
Regards, Antoine