Advertisement
prjbrook

spiMaster8.ino

Aug 23rd, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1.  
  2. // Based on Code Written by Nick Gammon// February 2011
  3. //TPA and B reading well from 1802. Now reading address from MA0..MA7 directly.Wed Jul 1 12:20:36 NZST 2020
  4. /*Sat Jul 4 13:29:59 NZST 2020. C:\Users\Dell\Documents\Arduino\PB_Sketches_May20\spiMaster6\spiMaster6.ino
  5.  
  6. */
  7. #include <SPI.h>
  8. #define TPAPin 8
  9. #define TPBPin 9
  10.  
  11. byte adrHi=0x12;
  12. byte adrLo=0x34;
  13.  
  14. void setup (void)
  15. {
  16. Serial.begin (115200);
  17. pinMode(TPAPin,INPUT);
  18. pinMode(TPBPin,INPUT);
  19. DDRD=0x0;
  20. DDRC=0x0;
  21. pinMode(SS, OUTPUT);
  22. //Serial.begin (115200); // debugging
  23. digitalWrite(SS, HIGH); // ensure SS stays high for now
  24. SPI.begin ();
  25. SPI.setClockDivider(SPI_CLOCK_DIV8); // Slow down the master a bit
  26. } // end of setup
  27.  
  28.  
  29. void loop (void) {
  30. if (digitalRead(TPAPin)==HIGH) {
  31. doTPAStuff();
  32. }
  33. if (digitalRead(TPBPin)==HIGH) {
  34. doTPBStuff();
  35. }
  36. }
  37.  
  38. void SPITx2(void) { //send two adresses via spi
  39. digitalWrite(SS, LOW); // SS is pin 10
  40. SPI.transfer(adrHi);
  41. delayMicroseconds(8); //2 microsecond delay seems to work but not 1 uS. Check nano when this comes up.
  42. SPI.transfer(adrLo);
  43. digitalWrite(SS, HIGH);
  44. } // -------------------end of loop
  45.  
  46.  
  47. void doTPAStuff(void) {
  48. adrHi = (PIND & 0xf0)| (PINC & 0x0f);
  49. while(digitalRead(TPAPin) ==HIGH) { }; //do nothing
  50. Serial.print("$");Serial.print(adrHi,HEX);
  51. }
  52. void doTPBStuff(void) {
  53. byte temp;
  54. adrLo= (PIND & 0xf0) | (PINC & 0x0f);
  55. temp = adrLo;
  56. SPITx2(); //send adrHi and adrLo to Nb
  57. while(digitalRead(TPBPin) ==HIGH) { }; //do nothing
  58. Serial.print(" ");Serial.println(adrLo,HEX);
  59. //Serial.print(" ! ");Serial.println(temp,HEX);
  60.  
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement