Go Down

Topic: Using USART0 and USART1 in SPI Master Mode or SPI Slave Mode (Read 273 times) previous topic - next topic

dlloyd

This is an attempt to establish 4-wire SPI signals on the Arduino Due's USART0 and USART1 peripherals.

To change the SPI Clock Mode or other parameters, the appropriate register values need to be changed. For the SPI_MASTER mode, I tested SCK, MOSI and CS at 1, 2, 4, 7, 12, 14 MHz with divisors of 84, 42, 21, 12, 7, 6 respectively. Interesting that the signals seemed OK at 21 and 28 MHz (using divisors of 4 and 3), but the data sheet says a divisor of 6 is the minimum.

The main hardware SPI + 2 embedded USART SPIs should allow 3 SPI processes occurring simultaneously. Some interesting possibilities - Directly connecting up to 5 SPI devices, or using the main SPI as normal while establishing Due-Due communication through USART SPI.

This is a diagram to show the connections. It could represent USART-USART self-test or Due-Due communication.



Attached are 4 sketches. Only the SPI Master versions were tested (sending byte 0xAA with 50┬Ás spacing), but the different sketches show some minor changes needed for configuration. The print monitor will display the status of various USART registers.

More development would needed to create a driver or library, but this is a start in order to establish the signals and perform testing.

I've made a start at translating the code from this useful link (it can be found in the comment section in each of the attached files).  Scroll down to "SPI from the USART ... an alternative"


bad_crc

Awesome!  I've been looking for info on how to set this up.   

 One question for you.  I grabbed your code for USART0 SPI master.  In it you set up the baud rate generator reg to 21 and in the status function you print it back out.

When I run that however, it always prints a value of 0 despite the register not listed as write-only in the spec.  Do you have the same issue in your setup?

check out my arduino interactive LED table
http://forum.arduino.cc/index.php?topic=275263.0

bad_crc

Nevermind, figured it out.

 Needed to enable the peripheral clock controller for USART0.  Getting the register values I expect now.
check out my arduino interactive LED table
http://forum.arduino.cc/index.php?topic=275263.0

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy