Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Based on Code Written by Nick Gammon// February 2011
- //TPA and B reading well from 1802. Now reading address from MA0..MA7 directly.Wed Jul 1 12:20:36 NZST 2020
- /*Sat Jul 4 13:29:59 NZST 2020. C:\Users\Dell\Documents\Arduino\PB_Sketches_May20\spiMaster6\spiMaster6.ino
- */
- #include <SPI.h>
- #define TPAPin 8
- #define TPBPin 9
- byte adrHi=0x12;
- byte adrLo=0x34;
- void setup (void)
- {
- Serial.begin (115200);
- pinMode(TPAPin,INPUT);
- pinMode(TPBPin,INPUT);
- DDRD=0x0;
- DDRC=0x0;
- pinMode(SS, OUTPUT);
- //Serial.begin (115200); // debugging
- digitalWrite(SS, HIGH); // ensure SS stays high for now
- SPI.begin ();
- SPI.setClockDivider(SPI_CLOCK_DIV8); // Slow down the master a bit
- } // end of setup
- void loop (void) {
- if (digitalRead(TPAPin)==HIGH) {
- doTPAStuff();
- }
- if (digitalRead(TPBPin)==HIGH) {
- doTPBStuff();
- }
- }
- void SPITx2(void) { //send two adresses via spi
- digitalWrite(SS, LOW); // SS is pin 10
- SPI.transfer(adrHi);
- delayMicroseconds(8); //2 microsecond delay seems to work but not 1 uS. Check nano when this comes up.
- SPI.transfer(adrLo);
- digitalWrite(SS, HIGH);
- } // -------------------end of loop
- void doTPAStuff(void) {
- adrHi = (PIND & 0xf0)| (PINC & 0x0f);
- while(digitalRead(TPAPin) ==HIGH) { }; //do nothing
- Serial.print("$");Serial.print(adrHi,HEX);
- }
- void doTPBStuff(void) {
- byte temp;
- adrLo= (PIND & 0xf0) | (PINC & 0x0f);
- temp = adrLo;
- SPITx2(); //send adrHi and adrLo to Nb
- while(digitalRead(TPBPin) ==HIGH) { }; //do nothing
- Serial.print(" ");Serial.println(adrLo,HEX);
- //Serial.print(" ! ");Serial.println(temp,HEX);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement