I’m an engineering student and I want to implement a communication between 2 arduino feather M0. The master can send bytes to slave, but this can’t do it. The slave sends only 0. I read the datasheet and I should write the tx-buffer of the slave when the interrupt flag DRE is activated. I can only read the SPI.DATA.reg but not write it. Can you help me please? This is the code of the master and slave.
MASTER.txt (952 Bytes)
SLAVE.txt (4.65 KB)
Please post a wiring diagram.
I can only read the SPI.DATA.reg but not write it.
Please define what that mean. Do you get a compiler error? Do you just think it don't work as you don't see the result on the other system?
Does the posted code compile for you? For me it doesn't which makes me believe that you didn't test with this code. Post actual code and it's output.
I read the datasheet ( http://ww1.microchip.com/downloads/en/DeviceDoc/40001883A.pdf ) and in page 406 I must write the Data register of the slave (in the code: sercom4->SPI.data.reg) to update the TX-buffer.
I test the code and Master sends bytes and slave receives the correct data. Instead slave don’t receive the correct data.
There is not compile errors. There are the wiring diagram and connections between the 2 arduino.
Master2.0.ino (3.01 KB)
Slave2.0.ino (7.65 KB)
I test the code and Master sends bytes and slave receives the correct data. Instead slave don't receive the correct data.
If the received data is not correct, please post the data it receives.
I'm not sure if the SAMD processor allows Serial methods to be called in interrupt context.
I removed the serial methods from the interrupt routine. I tested the code again.I want to receive data = 20 from the slave. Instead the master receives only 0 on the MISO. So I think that I can't write the register SERCOM4->SPI.data.reg to update the TX-buffer of the slave, but I don't understand why.
Thank you very much for your help.
Change the value you set the SERCOM4->SPI.data.reg to from 'data' to a fixed value (p.e. 20). Check again. What do you receive on the master?
I took your advice but the master receives only ‘0’ .
Then I tested the single pins (MOSI->pin 23, MISO->pin 22). Using pinMode and digitalWrite statements, I generate a square wave and whit MOSI it works but with MISO I read only ‘0’. Is there a malfunction on the pin 22-MISO? I will test whit an oscilloscope to better understand.
FeatherM0 PINOUT: Adafruit Learning System
Did you solve the problem? I am facing the same problem. Thanks.