Hello good afternoon
My name is Adrian, I am trying to learn about ARDUINO’s projects, and I I'm stuck about how to TRANSFER data between SLAVE to MASTER using SPI.
Initially I connected an ARDUINO NANO as MASTER to an ARDUINO ONE as SLAVE, using the pins ->
pin 10 (SS) -> Green
pin 11 (MOSI) -> Gray
pin 12 (MISO) -> Orange
pin 13 (SCK) -> Cyan
- 5v (if required) -> Red
GND (for signal return) -> Black
I have attached a squematic in PDF.
I have obtained these components in BANGGOOD:
Links: https://www.banggood.com/
-> Geekcreit® UNO R3 ATmega328P Development Board For Arduino No Cable
-> Geekcreit® ATmega328P Nano V3 Controller Board Compatible Arduino Improved Version Module
On my first POST I have received an answer on how transfer FLOATS using:
union{
float rxmyTemp;
byte rxmyTempArray[4];
} data1, data2;
but when I tried to send TWO float numbers between MASTER & SLAVE, I’ve got good transmission data, if both numbers was temperature data, but garbage if I intented to send temperature and humidity (also both float numbers), so I decide to investigate with SPI.transfer16(unsigned int data)
Perhaps, I have the same problem with the unsigned integer, so I try to explain with details...
Problem: TRANSFER & RECEIVE unsigned Integer from SLAVE to MASTER, using SPI.transfer16(unsigned int data)
When the MASTER requests it (sending ONE unsigned int <11>, or <12>, or not matter wich number send at this moment, I'll hope obtain an Unsigned INT, sending from the SLAVE, and watch the Receiving: masterSEND number in the Serial Monitor (COMM 10) associated to the MASTER.
SEND <11> I expect received
SEND <12> I expect received
SEND <13> I expect received
SEND <21> I expect received and so on...
In order to VERIFY what number is SENDING, and what number is RECEIVING, I thought that is was easy to SEND sequential Unsigned Integer from 250 to 800, viewing each pair of numbers at
• Slave Serial Monitor (COMM14) or
• Master Serial Monitor (COMM10).
Why 250 ¿???
Because, from [0 to 255], there was NO problem, the MSBFIRST byte, arraived from SLAVE to MASTER.
//If I send -> 250(decimal) -> 00 00 00 FA (hex) -> FROM SLAVE >>>>>
13:52:00.110 -> slaveSEND= 250
13:52:00.110 -> hex= 00 00 00 FA
// I MUST RECEIVED at MASTER <<<<<<<<<<<<<<<<<<<<<<<
13:52:04.185 -> masterRECEIVED= 64000 hex= 00 00 FA 00 Swap-> 250
IT IS WORK OK ¡!!!!!!!!!!!!!!!!!!!!!
but when I send 256 ...
// 256 (decimal) -> 00 00 01 00 (hex) -> FROM SLAVE >>>>>
13:52:12.446 -> slaveSEND= 256
13:52:12.446 -> hex= 00 00 01 00
// The number I received in hex was 00 00 00 00 (cero) not -> 00 00 01 00!!!!!
13:52:16.523 -> [b]masterRECEIVED = 0 hex= 00 00 00 00[/b] Swap-> 0
If you continue with the loop from [250 ->800], you could watch, what I’m watching in the Serial Monitor. These are the output from Master & Slave.
MASTER Output
13:43:27.399 -> Master-Digest-01cRandom.ino
13:43:27.399 -> Versión N°: 01c
13:43:27.435 -> Ultima modificación: 30/09/2019 09:30
13:43:27.470 -> tA= 64768 hex= FD00 masterRECEIVED-> 253
13:43:29.499 -> tA= 32907 hex= 808B masterRECEIVED-> 35712
13:43:31.542 -> tA= 65024 hex= FE00 masterRECEIVED-> 254
13:43:33.618 -> tA= 256 hex= 100 masterRECEIVED-> 1
13:43:35.662 -> tA= 512 hex= 200 masterRECEIVED-> 2
13:43:37.694 -> tA= 768 hex= 300 masterRECEIVED-> 3
// was removed for space !!!!!!!!!!!!!
13:52:04.185 -> tA= 64000 hex= FA00 masterRECEIVED-> 250
13:52:06.228 -> tA= 64256 hex= FB00 masterRECEIVED-> 251
13:52:08.306 -> tA= 64512 hex= FC00 masterRECEIVED-> 252
13:52:10.338 -> tA= 64768 hex= FD00 masterRECEIVED-> 253
13:52:12.379 -> tA= 65024 hex= FE00 masterRECEIVED-> 254
13:52:14.447 -> tA= 65280 hex= FF00 masterRECEIVED-> 255
13:52:16.523 -> tA= 0 hex= 0 masterRECEIVED-> 0
13:52:18.550 -> tA= 256 hex= 100 masterRECEIVED-> 1
13:52:20.612 -> tA= 512 hex= 200 masterRECEIVED-> 2
13:52:22.647 -> tA= 768 hex= 300 masterRECEIVED-> 3
13:52:24.681 -> tA= 1024 hex= 400 masterRECEIVED-> 4
SLAVE Output
13:43:30.292 -> Slave-Digest-01c.ino
13:43:30.292 -> Versión N°: 01c
13:43:30.327 -> Ultima modificación: 30/09/2019 09:30
13:43:31.609 -> slaveSEND= 2
13:43:33.659 -> slaveSEND= 3
// ... was removed for space !!!!!!!!
13:52:08.346 -> slaveSEND= 254
13:52:10.411 -> slaveSEND= 255
13:52:12.446 -> slaveSEND= 256
13:52:14.513 -> slaveSEND= 257
I know that I must make a MISTAKE on my code, but I couldn’t find it, so if anybody could run it, perhaps show me the error, in the code, or in the CONCEPT of transfer data using SPI.transfer16(unsigned int data)
Well, this part is where I get lost.
Thank you very much for your time, I'll hope receive any suggest
Best regards,
Adrian
(Spanish spoken)
MasterSlave_SPI.Transfer16.pdf (710 KB)
Master_S_Transfer16.ino (11.8 KB)
Slave_M_Transfer16.ino (4.33 KB)
tempDHT11.H (4.23 KB)