SPI transfer problem | Arduino Compatible Compiler for LabVIEW Discussions | Forum

Avatar
Please consider registering
guest
sp_LogInOut Log In sp_Registration Register
Register | Lost password?
Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Feed Topic RSS sp_TopicIcon
SPI transfer problem
December 19, 2019
3:03 pm
Avatar
Muzikansky
Member
Members
Forum Posts: 9
Member Since:
December 11, 2019
sp_UserOfflineSmall Offline

Hello

I am trying to control serial DAC (AD5530) by Uno board. I set CS pin 10. I tested with scope :

  1. At pin13 (clock) there are 600ns 8 clocks. I tried to change Clock Divider parameter to change clock width but it did not affected. How can I change clock width?
  2. Pin 11 (MOS) is always zero and not affected by transferred data.

D_A.vi is attached. This vi is based on MAX6675 Thermocouple to Digital Converter example.

December 20, 2019
9:56 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

First of all, you are not using the clock divider correctly.  Take a look at the comments of MAX6675 Thermocouple to Digital Converter.vi.  For the Uno, there are only discrete settings as explained here.

https://www.arduino.cc/en/Refe.....ockDivider

They are #defines in the SPI library.  So for divide by 8, you would use a value of 5.  You have a value of 42 in the VI.   

#define SPI_CLOCK_DIV4 0x00
#define SPI_CLOCK_DIV16 0x01
#define SPI_CLOCK_DIV64 0x02
#define SPI_CLOCK_DIV128 0x03
#define SPI_CLOCK_DIV2 0x04
#define SPI_CLOCK_DIV8 0x05
#define SPI_CLOCK_DIV32 0x06
#define SPI_CLOCK_DIV64 0x07

 

Also, you do not have a "Last" transfer mode, only "Continue".  This will never end the transaction.  This can be seen in the MAX6675 Thermocouple to Digital Converter.vi example.

December 22, 2019
12:28 pm
Avatar
Muzikansky
Member
Members
Forum Posts: 9
Member Since:
December 11, 2019
sp_UserOfflineSmall Offline

I changed devider parameter to 03 and clock width is increased.

I corrected second transfer to "Last" and at MOS (pin 11) I see pulses. SPI seems working.

 

Thanks.

December 26, 2019
12:41 pm
Avatar
Alan Kitching
Member
Members
Forum Posts: 9
Member Since:
August 16, 2019
sp_UserOfflineSmall Offline

Hi.

 

I have been using the Arduino Compiler for LabVIEW in an attempt to communicate with a Microchip MCP3208 A/D converter (datasheet http://ww1.microchip.com/downl.....21298e.pdf )

The attached VI “Learn SPI” contains the code which I believe should have worked.

However, the resulting SPI waveform had gaps of 5mS between each group of 8 pulses.

The "Detailed Help” for the SPI Transfer function, it states that  “There is an automatic a 5ms delay after the slave select line is lowered before issuing the SPI transfer."

There is no indication in the Help text  that this delay is included at the start of every SPI Transfer, even when the SS / CS line remains low, as in a “Continue” mode.

The data-sheet for the MCP3208 states that the SPI transfer must be completed within 1.2ms to meet the specification, which I do not seem able to achieve with the current ACfL SPI Functions

As a temporary work around and to confirm my understanding of the problem I checked the INO code, and commented out the "Delay(5)” commands

With these delays commented out, the resulting code worked as expected with only about a 6us gap between the three groups of SPI clock pulses. 

Obviously this workaround is not practical for a SubVI which is going to be embedded in a higher level VI.

I have sent a Private Message to Tech Support and anticipate that the reply will also be posted here.  I hope this helps someone else

December 26, 2019
8:27 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

It is not super clear but the 5ms is added to all transactions since the slave select line is lowered, or held low, for all transactions.  Since the peripheral does not control the CS line on AVR targets, this delay was intended to resolve some timing issues with certain SPI devices used by the Compiler.  This obviously is not a catch all solution.  You have a couple options:

1) Non-AVR targets, like the SAM core, control the CS line automatically so this delay does not occur.  Switching targets may not be an option for you.

2) It is always best to use a specific Arduino library for a device when one is available.  There is a library for your ADC lined below.  Then you can simple create a wrapper for the Compiler to access the APIs and you dont have to worry about the SPI communication.  There is an example that is shipped with the Compiler for the Digilent Analog Shield which has a very similar ADC.  You could likely copy that and change the API calls for this library instead.

https://github.com/MajenkoLibr.....es/MCP3208

December 27, 2019
2:19 pm
Avatar
Alan Kitching
Member
Members
Forum Posts: 9
Member Since:
August 16, 2019
sp_UserOfflineSmall Offline

Thanks for the advice and guidance.

I have found all the instructions in the Compiler Manual 

A.K.

December 27, 2019
4:29 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

Correct, it is in the section titled "Porting an Arduino Library to LabVIEW" of the user manual.

November 9, 2020
1:53 pm
Avatar
Philip
New Member
Members
Forum Posts: 2
Member Since:
December 16, 2019
sp_UserOfflineSmall Offline

Steffan said
It is not super clear but the 5ms is added to all transactions since the slave select line is lowered, or held low, for all transactions.  Since the peripheral does not control the CS line on AVR targets, this delay was intended to resolve some timing issues with certain SPI devices used by the Compiler.  This obviously is not a catch all solution.  You have a couple options:

1) Non-AVR targets, like the SAM core, control the CS line automatically so this delay does not occur.  Switching targets may not be an option for you.

2) It is always best to use a specific Arduino library for a device when one is available.  There is a library for your ADC lined below.  Then you can simple create a wrapper for the Compiler to access the APIs and you dont have to worry about the SPI communication.  There is an example that is shipped with the Compiler for the Digilent Analog Shield which has a very similar ADC.  You could likely copy that and change the API calls for this library instead.

https://github.com/MajenkoLibr.....es/MCP3208

  

Hi Steffan,

I am having the same issue of 5ms delay between every byte though it is hold low for full frame 10 byte. How can this 5ms be manipulted/edit? Where it is located? I havent seen anything in the SPI.h. Any work around except for changing the board? I was not expecting this behavour as long as I keep the CS low.

Thank you.

Forum Timezone: UTC 0
Most Users Ever Online: 100
Currently Online:
28
Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
miche91: 33
scottj: 28
scadao: 23
Member Stats:
Guest Posters: 5
Members: 202
Moderators: 0
Admins: 3
Forum Stats:
Groups: 1
Forums: 2
Topics: 266
Posts: 1222
Newest Members:
pujacontrol
Administrators: geadmin: 22, filipealtoe: 96, Steffan: 356