Project

General

Profile

(Resolved) Simple test using atmega328 - problem with crc

Added by 4994james almost 6 years ago

Hi I am quite new to this so please forgive me if this is obvious. I have successfully used this tx rx code example. However as soon as try to build an even simpler example things go awry. Here is my code:

tx:
#include 
char payload[] = "abcdefghijklmnopqrstuvwxyz";
void setup () {
    Serial.begin(9600);
    rf12_initialize(10, RF12_433MHZ, 210);
    pinMode(13,OUTPUT);
}
void loop () {  
    rf12_recvDone();
    rf12_sendStart(0, &payload, sizeof payload);
    delay(1000);
}

rx:
#include 
void setup () {
    Serial.begin(9600);
    rf12_initialize(30, RF12_433MHZ, 210);
}
void loop () {
    if (rf12_recvDone()){
        Serial.println("recvdone");
        Serial.print("len: ");Serial.print(rf12_len);
        Serial.print("crc: ");Serial.println(rf12_crc);  
        for (byte i = 0; i < rf12_len; ++i)
        Serial.print(rf12_data[i]);
        Serial.println();
    }
}

Now I get crc errors on almost all packets received. E.g. typical output of serial monitor:
len: 27crc: 22784
9734991001011023510410510610710810912711148113114115116117501191201211220

I am pretty sure this is not a hardware problem as it works perfectly with the openenergy code.

Any help gratefully received.


Replies (7)

RE: Simple test using atmega328 - problem with crc - Added by jcw almost 6 years ago

Don’t call rf12_sendStart without checking rf12_canSend. Or replace it by the new rf12_sendNow.

RE: Simple test using atmega328 - problem with crc - Added by 4994james almost 6 years ago

Thanks for the reply. However even using sendNow I see the same behaviour unfortunately.

RE: Simple test using atmega328 - problem with crc - Added by padvinder95 almost 6 years ago

What is your problem though? Is the CRC incorrect?

RE: Simple test using atmega328 - problem with crc - Added by 4994james almost 6 years ago

Yes. I get CRC errors (i.e. CRC <> 0) on most transmissions, but not all. Probably 1 in 20 comes through ok.

I am still a bit stumped. Using the same code the modules perform perfectly when wired to arduino uno boards. When wired directly to atemga328 (with ext 16mhz crystal, 3v) the transmitter works (i.e. I get perfect results receiving onto a module wired to arduino) but not the receiver (i.e. transmitting from module wired to arduino but receiving onto direct wired module).

So now I do suspect, in fact, some kind of hardware or wiring error. But the modules are clearly not at fault. I can’t see anything obvious in the wiring and I can repeat the issue on 2 distinct test rigs (breadboard).

RE: Simple test using atmega328 - problem with crc - Added by 4994james almost 6 years ago

Some progress. Programming the chip on an arduino board and then transplanting onto my prototype works fine. Then reprogramming (with identical code) direct using the AVRISP programmer from Atmel Studio and I am back to the old problem. Somehow I am not programming the chip correctly. I have followed all the instructions to build the arduino core library etc. etc. so there is still some work to do to work out what I have done wrong here.

RE: Simple test using atmega328 - problem with crc - Added by 4994james almost 6 years ago

Further progress. Compiling the code using arduino IDE and programming the chip with the resulting hex file gives a working result. However programming the chip with the hex file as generated by Atmel Studio gives garbled reception and CRC errors as before. Still stuck but at least I now know there is something about the 2 compilers that is giving a different result. Has anyone any idea how I can troubleshoot this?

RE: Resolved - Simple test using atmega328 - problem with crc - Added by 4994james almost 6 years ago

Now solved. Schoolboy error. I wasn’t setting the F_CPU=16000000 correctly. Once done, it works perfectly.

    (1-7/7)