Page 1 of 1

Arduino Mega2560 SPI bug

Posted: Wed Feb 05, 2014 6:36 am
by STibor
Hello!
I am using Arduino circuit Mega2560 SPI data transfer.
I experienced the following problems:
If you set the SPI hardware does not work the other ports.
RB4 will set SPI chip enable pint set(not work) after initialization.
I watched the communication, there is CLK output SDO data output, only the chip enable output value does not change.


If the SPI software I use the Flowcode not saved bits set the output port.
DAC En $ PORTA.3
En NVM $ PORTA.4
En MOSI (SDO) $ PORTA.5
MISO En (SDI) $ PORTC.4
CLK $ PORTC.3
This configuration is always loaded.

Examples are:http://www.matrixmultimedia.com/mmforum ... 330#p56894

Re: Arduino Mega2560 SPI bug

Posted: Thu Feb 13, 2014 8:07 pm
by STibor
Hello!
No answer?

Re: Arduino Mega2560 SPI bug

Posted: Mon Mar 17, 2014 6:03 pm
by Benj
Hello,

Sorry this one must have slipped through my net.
If you set the SPI hardware does not work the other ports.
So your saying if you enable SPI hardware you cannot use any other I/O pins? Have you a program that replicates this bug?
RB4 will set SPI chip enable pint set(not work) after initialization.
I assume this means that RB4 is an I/O pin connected to the SPI CS pin but cannot be used because of the issue mentioned above.
I watched the communication, there is CLK output SDO data output, only the chip enable output value does not change.
So the SPI bus is working but nothing else?

The program you link to is set to software mode, I guess this is working as it should to provide the functionality shown in the video. So the problem is hardware SPI only.

Let me know if I've got anything wrong.

Re: Arduino Mega2560 SPI bug

Posted: Mon Mar 17, 2014 6:38 pm
by Benj
Hello,

I've done some investigation and the problem isn't anything to do with Flowcode, it's a feature of AVR! If you setup hardware SPI on an AVR device then it will automatically allow the Slave Select functionality even in Master mode?!

This means if the SS pin (RB0 on the Mega 2560) floats high then the SPI hardware will lock up every time. Outputting a 1 or 0 to the SS pin should force the pin into output mode and the issue should then go away. Testing on hardware then seems to work fine.

I could override this in the CAL code but this may break the functionality of anything you have on the SS pin which might not be ideal.

Re: Arduino Mega2560 SPI bug

Posted: Mon Mar 17, 2014 7:40 pm
by STibor
Hi!
My English is bad for me, it was not possible to understand description of the problem.
The SPI master mode, use it.

Software SPI works, but does not save the port settings.
Hardware SPI with the clock and the data goes and blocks the ports so that the CS is always high.
See the hardware and SS output that works with any communication.
This means that if you run the SPI communication, ports are blocked?

Edit: PB0 it works with hardware SPI Chip Enable port.

Re: Arduino Mega2560 SPI bug

Posted: Tue Sep 05, 2017 12:09 am
by jorge66
Hello, I am using ARDUINO MEGA 2560 R3 and I am connecting it to AD7606 (ADC analog to digital converter). I am using SPI and set initialization by Hardware: freq. clk=fosc/2 but it does not run as expected in 8Mhz, instead it runs at 510Khz (too slow for my application). I do not have any other problem, except that my SPI clock is too slow because I want to receive serial comm bit by bit. Can you tell me what to do? Thank you!!!

Re: Arduino Mega2560 SPI bug

Posted: Tue Sep 05, 2017 12:51 am
by jorge66
Hello, I am using ARDUINO MEGA 2560 R3 and I am connecting it to AD7606 (ADC analog to digital converter). I am using SPI and set initialization by Hardware: freq. clk=fosc/2 but it does not run as expected in 8Mhz, instead it runs at 510Khz (too slow for my application). I do not have any other problem, except that my SPI clock is too slow because I want to receive serial comm bit by bit. Can you tell me what to do? Thank you!!!