Arduino Mega2560 SPI bug

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
User avatar
STibor
Posts: 263
Joined: Fri Dec 16, 2011 3:20 pm
Has thanked: 116 times
Been thanked: 113 times
Contact:

Arduino Mega2560 SPI bug

Post 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

User avatar
STibor
Posts: 263
Joined: Fri Dec 16, 2011 3:20 pm
Has thanked: 116 times
Been thanked: 113 times
Contact:

Re: Arduino Mega2560 SPI bug

Post by STibor »

Hello!
No answer?

User avatar
Benj
Matrix Staff
Posts: 15191
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4759 times
Been thanked: 4295 times
Contact:

Re: Arduino Mega2560 SPI bug

Post 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.

User avatar
Benj
Matrix Staff
Posts: 15191
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4759 times
Been thanked: 4295 times
Contact:

Re: Arduino Mega2560 SPI bug

Post 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.

User avatar
STibor
Posts: 263
Joined: Fri Dec 16, 2011 3:20 pm
Has thanked: 116 times
Been thanked: 113 times
Contact:

Re: Arduino Mega2560 SPI bug

Post 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.

jorge66
Posts: 3
Joined: Mon Jun 27, 2016 3:49 pm
Contact:

Re: Arduino Mega2560 SPI bug

Post 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!!!

jorge66
Posts: 3
Joined: Mon Jun 27, 2016 3:49 pm
Contact:

Re: Arduino Mega2560 SPI bug

Post 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!!!

Post Reply