Hi all,
I have been trying to get two of these talking to each other using two Arduino Diecimila boards (one for each) with no luck :(.
I am confident that my code is configuring the modules correctly because the DR1 goes high once I program in the Shockburst rx config bytes. However, all it picks up is garbage, and when I use 5 bytes of address length and 16 bit CRC the receiver does not pick up anything (filters the garbage it was picking up but still no real data)… My xmitter sends easy to detect bit sequence (A5s) - too simple not to be detected by the rcvr thats 15cm (6inches) apart.
This is my code below I hope somebody can help me.
XMITTER CODE:
int CE = 8;
int CS = 9;
int CLK = 10;
int D = 11;
byte pl[] ={0x11,0x22,0x33,0x44,0xE7,
0xA5,0xFF,0xA5,0xFF};
void toggle(int pin){
if(digitalRead(pin) == LOW) digitalWrite(pin,HIGH);
else digitalWrite(pin,LOW);
}
void wait(int i){delayMicroseconds(i);}
void sendPacket(byte *b, int c){
digitalWrite (CE, HIGH);
digitalWrite (CS, LOW);
digitalWrite (CLK, LOW);
//delay(200);
int i = 0;
for(i=0; i<c; i++){
digitalWrite(D, (b[(int)(i/8)] & (0x80>>(i%8))));
wait(1);
digitalWrite(CLK,HIGH);
wait(1);
digitalWrite(CLK,LOW);
}
digitalWrite(D,LOW);
digitalWrite (CE, LOW); //PULL LOW TO INITIATE TX
delay(100);
}
void init_tx(byte *b, int c){
pinMode(CLK, OUTPUT);
pinMode(CE, OUTPUT);
pinMode(CS, OUTPUT);
pinMode(D, OUTPUT);
digitalWrite(CE,LOW);
digitalWrite(CS,HIGH);
delayMicroseconds(3000);
for(int i =0; i<c; i++){
digitalWrite(D, (b[(int)(i/8)] & (0x80>>(i%8))));
wait(50);
digitalWrite(CLK,HIGH);
wait(50);
digitalWrite(CLK,LOW);
}
wait(40);
digitalWrite(CS,LOW);
digitalWrite(D,LOW);
digitalWrite(CLK,LOW);
//digitalWrite(CE,HIGH);
delay(1000);
}
void setup() {
pinMode (CE, OUTPUT);
pinMode (D, OUTPUT);
byte cfg[] = {0x20,0x20,0x11,0x22,0x33,0x44,0xE7,
0x11,0x22,0x33,0x44,0xE7,0xA3,0x4F,0xAE};
init_tx(cfg, 120);
digitalWrite (CE, HIGH);
digitalWrite (D, LOW);
delayMicroseconds(200);
digitalWrite(13,HIGH);
}
void loop (){
sendPacket(pl, 72);
delay(1000);
toggle(13);
}
RCVR CODE:
int CE = 8;
int CS = 9;
int CLK = 10;
int D = 11;
int DR1 = 7;
int debug = 13;
boolean temp = 0;
long pl = 0;
int count = 0;
void wait(int i){
delayMicroseconds(i);
}
void init_rx(byte *b, int c){
pinMode(CLK, OUTPUT);
pinMode(CE, OUTPUT);
pinMode(CS, OUTPUT);
pinMode(D, OUTPUT);
pinMode(DR1, INPUT);
digitalWrite(CE,LOW);
digitalWrite(CS,HIGH);
delay(300);
for(int i =0; i<c; i++){
digitalWrite(D, (b[(int)(i/8)] & (0x80>>(i%8))));
wait(10);
digitalWrite(CLK,HIGH);
wait(10);
digitalWrite(CLK,LOW);
wait(5);
}
wait(40);
digitalWrite(CS,LOW);
digitalWrite(D,LOW);
digitalWrite(CLK,LOW);
digitalWrite(CE,HIGH);
pinMode(D, INPUT);
pinMode(CLK, OUTPUT);
pinMode(DR1, INPUT);
}
byte getPl(){
//This function gets only the LSByte.
Serial.println("****In getpl()");
byte rx_pl = 0x00;
digitalWrite(CE, LOW);
while(digitalRead(DR1) == HIGH){
rx_pl <<= 1;
if(digitalRead(D)) {rx_pl |= 0x01;}
digitalWrite(CLK, HIGH);
wait(10);
digitalWrite(CLK, LOW);
wait(10);
}
digitalWrite(CE, HIGH);
return rx_pl;
}
void setup(){
byte cfg[] = {0x20,0x20,0x11,0x22,0x33,0x44,0xE7,
0x11,0x22,0x33,0x44,0xE7,0xA3,0x4F,0xAF};
init_rx(cfg, 120);
/*
byte cfg[] = {0x0F,0xFF};
init_rx(cfg, 16);
pinMode(CLK, INPUT);
*/
wait(202);
digitalWrite(debug,HIGH);
delay(1000);
digitalWrite(debug,LOW);
delay(1000);
digitalWrite(debug,HIGH);
delay(3000);
Serial.begin(19200);
Serial.println("****Begin -- ");
}
void loop(){
byte temp = 0x18; //Debug Val
delay(100);
if(digitalRead(DR1) == HIGH) {
temp = getPl();
Serial.print("****Left getpl() -- 0x");
Serial.println(temp, HEX);
}
}
I am using my PC desk to work on these modules so the interference is high (Router, wireless mouse/KB, speakers). Can somebody try this pair of codes on their setup please. If you only have one Arduino you can combine the two - just copy and paste the functions.
Thanks in advance.