MajenkoLibraries / ICSC

Inter-Chip Serial Communications
BSD 3-Clause "New" or "Revised" License
81 stars 27 forks source link

Function Send() not working - hardware seral atmega2560 #14

Closed slavi888 closed 5 years ago

slavi888 commented 5 years ago

Sorry for my not good English. I migrate from old version of library to new so I can use software serial. During migration I found that function Send() not working. This is on hardware serial Serial1 on arduino mega. Code stop at this function and waits until infinity. I research proglem and function waitForTransmitToComplete(); This function does flush of serial and here code "freezes"

void ICSC::waitForTransmitToComplete() { Serial.println("w 1"); if (_dePin == -1) //Skip flush return; Serial.println("w 2");

if defined(ARDUINO) && ARDUINO >= 100

if ARDUINO >= 104

// Arduino 1.0.4 and upwards does it right

Serial.println("w 3"); _dev->flush(); Serial.println("w 4");

else

// Between 1.0.0 and 1.0.3 it almost does it - need to compensate
// for the hardware buffer. Delay for 2 bytes worth of transmission.

Serial.println("w 5"); _dev->flush(); Serial.println("w 6");

delayMicroseconds((20000000UL/9600)+1);

Serial.println("w 7");

I can see control print Serial.println("w 5"); and not see Serial.println("w 6");

I think there is problem in line _dev->flush();

Can I comment this line? What is right way to continue use ICSC library? Thank you.

majenkotech commented 5 years ago

Are you calling send from within an interrupt by any chance?

slavi888 commented 5 years ago

I've found that I have to add to my code the following line Serial1. Begin (9600); Before ICSC. Begin (); That's because ICSC. Begin does not initialize serial port Now everything works fine. Thanks