SAM3X8E USART in SPI mode (Reception)

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, in my previous post I was able to get 16-bit data on MOSI line (here). Now I moved to work on receiving data on MISO line. I am testing this with a SPI device and trying to receive some data. For which using AD5592, which has a feature of writing to some register and then reading them back to verify the SPI write operation done correctly. Tested communication with AD5592 by using native SPI and able to write and read back the register content of AD5592. Then worked on receiving the data with USART based SPI find the attachment. But not receiving anything. The data should be received in RHR but when polled RXRDY bit in the US_CSR register shows 0 indicating did not receive any data.

 

If I want to implement a USART receive handler how it can be done in Arduino Due?

 

In attachment

Signal in Green is SCK

Signal in Yellow is MOSI

Signal in Blue is MISO

Signal in Pink is CS

 

First two bytes are writing to AD5592 read configuration register with 0b1010000 00100000 to make CH5 as input. And next two bytes are for sending NOP (all 0's) to get the readback on MISO. It should read 0b100000.

Attachment(s): 

Last Edited: Wed. Mar 30, 2022 - 12:04 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What does MISO look like when it works with native SPI? And is this what MISO looks like when not connected to the SAM3X8E when you run with the USART? I guess I'm asking if there is a conflict on that signal,  it looks bad on the scope.

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Lars, I am attaching the waveforms captured using native SPI that communicates to AD5592.

And is this what MISO looks like when not connected to the SAM3X8E when you run with the USART?

I have connected AD5592 to SAM3X8E using USART SPI in the previous attachment.

 

In attachment

Signal in Green is MISO

Attachment(s): 

Last Edited: Thu. Mar 31, 2022 - 06:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am intrigued.   The SAM3XE has only got SPI0 but it has USART0, USART1, USART2 with available SCK pins.

 

On the Mega2560 they carefully removed access to all of the USART XCK pins.   Preventing you using any of the 4 USARTs in MSPI mode.

The Due can access PA17, PA16 but not PB24.   So you can use both USART0 and USART1 in SPI mode.

 

I don't see the problem.   The SPI0 peripheral can use 8-16 bits for SPI transfers.   The USART_SPI can only use 8 bit transfers.

 

If you want native 16-bit just use SPI0.

If you need to use the USART hardware pins,  just do two 8-bit transfers.

 

Both SPI0 and USARTn peripherals have TX and RX buffers.   Both can use DMA.

 

This is all from my reading of the datasheets.  I don't have intimate experience of SAM3XE.

 

It seems fairly unimportant for a handful of 16-bit transfers.    But would give impressive performance when or if you want to transfer millions of 16-bit data e.g. to graphics controller chips.

 

David.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi David, thanks for the input. I have achieved 16-bit communication now slightly unclear about the data reception using USART SPI.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SPI always writes TX and receives on RX.   i.e. the hardware always does a transfer.

 

So if you want to receive 16-bit you write a 8-bit dummies.   And read the two 8-bit data that was received.

 

The buffering makes it important that you do the correct number of writes and reads.   A simple way to implement this is to write a single 8-bit function:

uint8_t usart_spi_transfer(uint8_t c);

 

Then you always keep in step.

Most SPI devices require a command before you receive the appropriate response e.g.

     usart_spi_transfer(command);

     uint8_t hi = usart_spi_transfer(0);  //dummy

     uint8_t lo  = usart_spi_transfer(0); //dummy

     return (hi << 8) | lo;

 

Of course you can write a single uint16_t usart_spi_transfer16(uint16_t c);

using the previous example.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi David, thanks for your input. I am able to receive the data on MISO line now. But the problem I am facing is the received data can be seen on oscilloscope but when read the US_RHR won't show any data. But if I read the US_RHR after some delay or multiple times then the received data is reflecting in the US_RHR register. What may be wrong?