I've been working on a project to interface ENC28J60 with an ATmega16A µC. For the sake of debugging I have built a board with UART capability so that I can view the register values of the Ethernet controller chip on my laptop. I tried to establish communication with the ENC28J60 chip and my µC through SPI and was unable to get any sort of reading even though my code seemed to be correct as per the SPI commands listed in the ENC28J60 datasheet.
Now just to check my SPI code, I tried to establish communication b/w two ATmega16A µC as per this tutorial. But instead of displaying the received value on an LCD, I used UART to send the values to my laptop. But I made the following observations:
- each time, the master shows a different received value even though the slave is sending a constant value of 0x11.
- Transmission and reception happens only when I take my hand near the circuit and stops as soon as my hand is removed.
I googled about this a lot and found that SPI is highly susceptible to EMI. I took the following measures to reduce errors due to EMI.
- I slowed down the SPI clock.
- I've put a 470µF capacitor across the Vcc and GND to eliminate noise from the power supply.
- I've reduced the wire length of MOSI,MISO and SCK.
What other measures can I take to get reliable and consistent communication over SPI?
And is my MAX232 IC causing a lot interference to my SPI signals?
And will using UART simultaneously with SPI affect the SPI reliability?