4 years, 3 months ago.

Rx Interrupt wont work when converting to old mbed library

Using an MBED F767Zi. I need to use an old mbed library, revision 125, in order for SD file systems to work. However, doing so makes my Rx Interrupt function stop working. The problem seems to stem from the attach method. In revision 138 I wrote code as seen below. It works fine. However when I revert to the old library it breaks and stops printing once I call sendfakedata(). Commenting out attach fixes this. However, I obviously still need to attach an Rx_interrupt. Anyone know if I need to call it differently in this old library and how? Or how I could rewrite the attach function?

  1. include "mbed.h"

char rawdata[20];

int datacount = 0;

Serial pc(USBTX, USBRX);

Serial radio(PD_5, PD_6);

char* rawradiodata;

void sendfakedata(){

pc.printf("\n\r");

pc.printf("Sending Fake Data \n\r");

wait(.00104);

radio.putc('E');

wait(.00104);

radio.putc('1');

wait(.00104);

radio.putc('2');

wait(.00104);

radio.putc('3');

wait(.00104);

radio.putc('4');

wait(.00104);

radio.putc('5');

wait(.00104);

radio.putc('6');

wait(.00104);

radio.putc('7');

wait(.00104);

radio.putc('8');

wait(.00104);

radio.putc('I');

wait(.00104);

radio.putc('8');

wait(.00104);

radio.putc('7');

wait(.00104);

radio.putc('6');

wait(.00104);

radio.putc('5');

wait(.00104);

radio.putc('4');

wait(.00104);

radio.putc('3');

wait(.00104);

radio.putc('2');

wait(.00104);

radio.putc('1');

}

void Rx_Interrupt(){

while ((radio.readable()) && (datacount != 20)){

rawdata[datacount] = radio.getc();

  • (rawvradiodata+datacount) = radio.getc();

datacount = (datacount + 1);

}

return;

}

int main() {

radio.attach(&Rx_Interrupt, Serial::RxIrq);

int lengthdata = 2;

radio.format(9, SerialBase::Even, 1);

rawradiodata = (char*)malloc(lengthdata*sizeof(char)*9);

if(rawradiodata == NULL){

pc.printf("allocation failed\n\r");

}

memset(rawradiodata,'-',lengthdata*9);

for(int i = 0; i < lengthdata*sizeof(char)*9; i++)

{

pc.putc(rawradiodata[i]);

}

wait(2);

NVIC_DisableIRQ(USART2_IRQn);

NVIC_EnableIRQ(USART2_IRQn);

pc.printf("hi2");

sendfakedata();

pc.printf("\n\r");

pc.printf("Current buffer \n\r");

for(int i = 0; i < 18; i++)

{

pc.putc(rawradiodata[i]);

}

}

Sorry for the nauseating spaces; it was the only way I could format it.

1 Answer

4 years, 3 months ago.

Please, use "<<code>>" and "<</code>>" to format your code like that :

#include "mbed.h" 

char rawdata[20];

int datacount = 0;

Serial pc(USBTX, USBRX);

Serial radio(PD_5, PD_6);

char* rawradiodata;

void sendfakedata(){

pc.printf("\n\r");

pc.printf("Sending Fake Data \n\r");

wait(.00104);

radio.putc('E');

wait(.00104);

radio.putc('1');

wait(.00104);

radio.putc('2');

wait(.00104);

radio.putc('3');

wait(.00104);

radio.putc('4');

wait(.00104);

radio.putc('5');

wait(.00104);

radio.putc('6');

wait(.00104);

radio.putc('7');

wait(.00104);

radio.putc('8');

wait(.00104);

radio.putc('I');

wait(.00104);

radio.putc('8');

wait(.00104);

radio.putc('7');

wait(.00104);

radio.putc('6');

wait(.00104);

radio.putc('5');

wait(.00104);

radio.putc('4');

wait(.00104);

radio.putc('3');

wait(.00104);

radio.putc('2');

wait(.00104);

radio.putc('1');

}

void Rx_Interrupt(){

while ((radio.readable()) && (datacount != 20)){

rawdata[datacount] = radio.getc();

    (rawvradiodata+datacount) = radio.getc(); 

datacount = (datacount + 1);

}

return;

}

int main() {

radio.attach(&Rx_Interrupt, Serial::RxIrq);

int lengthdata = 2;

radio.format(9, SerialBase::Even, 1);

rawradiodata = (char*)malloc(lengthdata*sizeof(char)*9);

if(rawradiodata == NULL){

pc.printf("allocation failed\n\r");

}

memset(rawradiodata,'-',lengthdata*9);

for(int i = 0; i < lengthdata*sizeof(char)*9; i++)

{

pc.putc(rawradiodata[i]);

}

wait(2);

NVIC_DisableIRQ(USART2_IRQn);

NVIC_EnableIRQ(USART2_IRQn);

pc.printf("hi2");

sendfakedata();

pc.printf("\n\r");

pc.printf("Current buffer \n\r");

for(int i = 0; i < 18; i++)

{

pc.putc(rawradiodata[i]);

}

}

may be it would be nice using 'volatile' datas inside the interrupt...

http://www.embedded.com/electronics-blogs/beginner-s-corner/4023801/Introduction-to-the-Volatile-Keyword

May try to use inside the interrupt the available() method against the readable()...

posted by Raph Francois 19 Apr 2017