( I am reposting here, seems more appropriate than the end of the thread it was on )
I have a project that sends 19 numbers from a wireless remote control ( working fine ) to a decoder/display unit via VirtualWire.
Sometimes it just freezes, there is no data coming out of the micro ( using Shiftout ) but the signal from the RF receiver is fine.
Tonight all the displays decided to blank, when I sent an update from the remote again it worked fine, but last night it just froze with numbers displayed. When I switched the power on and off it worked again.
Can anyone see in my code why it should hang up?
It reads the switch data, compares the PIN numbers ( a security address ) then I sort out the displays that need leading zero blanking, plus I check to see if switches 7 and 8 are set to 0, ( which is how I put the displays into standby ) and then it shiftsout to the 19 shift registers.
I put the flushing bit in when I had the previous problem, I dont think it can do any harm ?
There is a shift register clear pin on the TPIC display chips, but I am not using that ( or the notG pin for blanking ) due to pcb layout simplicity. heres the code:-
// 19 digit receiver
// tile order set by old pcb layout of plugs HGDABCEFSRQPONMLKJI link across gap data inout
// try flushing SR before sending new lot to get rid of intermittent wrong displays
#include <VirtualWire.h>
#define latchPin 19 // rck
#define clockPin 18 // sck
#define dataPin 16 // ser in
int Rxpin;
int PIN;
int tile [19];
int SW0Pin = 3; // bits to read in unique address - LSB
int SW1Pin = 4; // bits to read in unique address
int SW2Pin = 5; // bits to read in unique address
int SW3Pin = 6; // bits to read in unique address - MSB
int address = 0; // bits put together afteer reading switches
int add0;
int add1;
int add2;
int add3;
const byte digitTable [10] = {
B01111110, B00110000, B01101101, B01111001, B00110011, // orig without text switching
B01011011, B01011111, B01110000, B01111111, B01111011};
const byte blank = B00000000;
void setup()
{
pinMode(SW0Pin, INPUT); // LSB of remote Address
digitalWrite(SW0Pin, HIGH);
byte add0 = 0; // read the value of SW0
pinMode(SW1Pin, INPUT); // LSB+1
digitalWrite(SW1Pin, HIGH);
byte add1= 0;
pinMode(SW2Pin, INPUT); // LSB+2
digitalWrite(SW2Pin, HIGH);
byte add2 = 0;
pinMode(SW3Pin, INPUT); // MSB of address
digitalWrite(SW3Pin, HIGH);
byte add3 = 0;
add3 = !digitalRead(SW3Pin);
add3 = add3 << 3;
add2 = !digitalRead(SW2Pin);
add2 = add2 << 2;
add1 = !digitalRead(SW1Pin);
add1 = add1 << 1;
add0 = !digitalRead(SW0Pin);
address = address|add3;
address = address|add2;
address = address|add1;
address = address|add0;
Rxpin = address;
Serial.println("Rx PIN is: ");
Serial.println(Rxpin, BIN);
Serial.println("testing");
Serial.begin(9600); // Debugging only
Serial.println("setup");
pinMode ( latchPin, OUTPUT);
pinMode ( clockPin, OUTPUT);
pinMode ( dataPin, OUTPUT);
vw_set_rx_pin(9); // set Rx
vw_setup(2400); // Bits per sec
vw_rx_start();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop ()
{
// CHECK FOR INCOMING MESSAGE
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
delay (20);
if (vw_get_message(buf, &buflen)) // Non-blocking
{
Serial.println("Got: "); // Show on PC for debugging
// CHECK IF PIN NUMBERS MATCH
PIN = buf[0]; // read Tx PIN number from buffer 0
if ( PIN == Rxpin ) { // everything below only runs if PINs match
Serial.println(" PINs match ") ;
for ( int t =1 ;t<=19;t++ ) {
tile [t] = buf [t];
show ();
}
} // end of if PINs match
}// end of if message received
} // end of loop
void show ()
{ // display numbers generated depending on leading zero blanking requirements of each group of displays
int dnumber = digitTable [ tile [3] ]; // single digit , no LZblanking
/////////////////////////////////////////////////////
int gnumber = (tile [2]) ? digitTable [ tile [2]] : 0; // leading zero blanking
int hnumber = digitTable [tile [1]];
////////////////////////////////////////////////////
int enumber = (tile [7]) ? digitTable [ tile [7]] : 0; // leading zero blanking
int fnumber = digitTable [tile [8]];
////////////////////////////////////////////////////
int rnumber = (tile [10]) ? digitTable [ tile [10]] : 0; // leading zero blanking
int snumber = digitTable [tile [9]];
////////////////////////////////////////////////////
int anumber = ( tile [4]) ? digitTable [ tile [4] ] : 0;
int bnumber = ( tile [4]|| tile [5]) ? digitTable [ tile [5]] : 0; // leading zero blanking
int cnumber = digitTable [tile [6]];
///////////////////////////////////////////////////////
int onumber = ( tile [13]) ? digitTable [ tile [13] ] : 0;
int pnumber = ( tile [13]|| tile [12]) ? digitTable [ tile [12]] : 0; // leading zero blanking
int qnumber = digitTable [tile [11]];
////////////////////////////////////////////////////
int lnumber = ( tile [16]) ? digitTable [ tile [16] ] : 0;
int mnumber = ( tile [16]|| tile [15]) ? digitTable [ tile [15]] : 0; // leading zero blanking
int nnumber = digitTable [tile [14]];
////////////////////////////////////////////////////
int inumber = ( tile [19]) ? digitTable [ tile [19] ] : 0;
int jnumber = ( tile [19]|| tile [18]) ? digitTable [ tile [18]] : 0; // leading zero blanking
int knumber = digitTable [tile [17]];
////////////////////////////////////////////////////
if ( tile [7] || tile [8] ) { // if switches 7 and 8 set to 00 blanks all displays
///////////////////////////////////////////////////
digitalWrite(latchPin, LOW);
for ( int k=0; k<=20; k++ ){ // flush out shift register
shiftOut(dataPin, clockPin, LSBFIRST, blank);
}
delay (20);
shiftOut(dataPin, clockPin, LSBFIRST, hnumber);
// delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, gnumber);
//delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, dnumber);
//delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, anumber);
//delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, bnumber);
//delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, cnumber);
//delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, enumber);
//delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, fnumber);
//delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, snumber);
// delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, rnumber);
//delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, qnumber);
//delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, pnumber);
// delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, onumber);
//delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, nnumber);
//delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, mnumber);
// delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, lnumber);
// delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, knumber);
// delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, jnumber);
// delay (5);
shiftOut(dataPin, clockPin, LSBFIRST, inumber);
delay (5);
digitalWrite(latchPin, HIGH);
}
else {
digitalWrite(latchPin, LOW); // blanking all displays
for ( int k=0; k<=20; k++ ){
shiftOut(dataPin, clockPin, LSBFIRST, blank);
}
digitalWrite(latchPin, HIGH);
}
} // end of showT function