Go Down

Topic: DUE: TX3 in SPI mode? (Read 1 time) previous topic - next topic

Psyco

Hi,

I'm using an Arduino Due (clone) and want to run the UART3 (RX3/TX3) port in SPI mode - is that possible?

  • I need only the TX3 pin to send out bytes at a given baud rate (without start and stop bits!), I don't need the clock line.
  • I can't do bitbanging (CPU is busy) and all other SPI/UART ports are also already in use.
  • The SAM3X8E comes in different packages: The 217-pin package has the UART3 with clock3 pin, so SPI-mode is supported. The Due uses the 144-pin package, with TX3/RX3 pins but the clock3 pin is not broken out.


I guess the actual chip inside the package is always the same, but does it "know" that the clock3 line is not connected to a pin?

So, can I just use the UART3 port in SPI mode (with all its limitations) or will the chip prevent that mode because it knows its pin configuration?

(Or will that even damage the chip?)

ard_newbie

#1
Mar 29, 2018, 12:38 pm Last Edit: Mar 29, 2018, 01:41 pm by ard_newbie
USART0 and USART1 can be used in SPI mode as master or slave, IMO USART3 can be used in SPI mode as slave only. An alternative would be using an DUE compatible board with all pins broken out such as the TAIJUINO.

Edit: With a bit of luck, USART3 could work as a master by using PMC_PCK with, e.g. a clock of MCK/8 and  USART0->US_BRGR = US_BRGR_CD(8 ); I guess PMC_PCK will precisely mimic SCK3. I didn't test it though.

Psyco

I can't find anything in the datasheet why the USART3 should be any different than the other - where did you get that information from?

I'm using an Arduino due clone - Due Core - with all pins from the chip (144-pin package) accessible.


As written above: I don't need the clock line (the port has to run in master mode).

ard_newbie

I don't understand how you can make an SPI master work without a clock line...

Page 802:
Serial Clock (SCK): This control line is driven by the master and regulates the flow of the data bits. The master may transmit data at a variety of baud rates. The SCK line cycles once for each bit that is
transmitted.


Page 773:
SCK3 is PE16 . The 144 pins Sam3x8e has only PIOA,B,C and D.

This is the reason why I suggest to replace the output SPI master clock by a PMC_PCK.

Psyco

I know that the 144-pin package has no SCKL3 pin - see my first post.

I just need the data output, the device receiving it doesn't need a clock line.


I want to drive the USART3 port in SPI master mode, the clock line will not be connected, I only want to send data without any control bits. Will the SAM3X8E (144-pin) accept this or refuse to set the SPI mode?

ard_newbie

#5
Mar 29, 2018, 06:17 pm Last Edit: Mar 29, 2018, 06:18 pm by ard_newbie
Of course you can always set USART3 in SPI master Mode, but I still don't understand how all this will work without a clock  :o  

Here is a code to set USART0 in SPI master Mode, change the output lines (See page 773) and replace USART0 by USART3:

Code: [Select]

void USART0Init(void) { // SPI Master

  // Output lines driven by the peripheral (MOSI, CS, SCK)
  PIOB->PIO_PDR |= PIO_PB25A_RTS0;        // CS
  PIOA->PIO_PDR |= PIO_PA17B_SCK0         // SCK
                   | PIO_PA11A_TXD0;      // MOSI
  PIOA->PIO_ABSR |= PIO_PA17B_SCK0;       // Peripheral type B

  // USART0 SPI Master
  PMC->PMC_PCER0 |= PMC_PCER0_PID17;       // USART0 power ON
  
  USART0->US_MR |= US_MR_USART_MODE_SPI_MASTER
                   | US_MR_CPOL       // CPOL = 1
                   | US_MR_CPHA       // CPHA = 1
                   | US_MR_CHRL_8_BIT
                   | US_MR_CLKO;
  USART0->US_BRGR = US_BRGR_CD(6); // Baud rate = 84MHz/6 = 14 MHz < 20 MHz
  USART0->US_CR = US_CR_RXEN       // Enable Receiver and Transmitter
                  | US_CR_TXEN;
}




Psyco

#6
Mar 29, 2018, 08:19 pm Last Edit: Mar 29, 2018, 08:20 pm by Psyco
So, the chip will not prevent me setting the SPI mode, even when the pin package does not support it on that port - good.

Thanks for the sample code.

Could this damage the chip/USART bus?


I need that "strange" output to communicate with LANC devices - all communication stuff (e.g. stop bits) are send by the device, even when its receiving data. The Arduino can only send bare data bits. Its a very odd protocoll - but I can't change that. Receving data on the Arduino will be the RX3 pin, but in normal serial mode. And to make it worse, some extra bits will be "read" by an extra I/O pin, to get the timing right.
So, if you really want to understand "why", try to built a LANC controller using an USART bus.

ard_newbie

#7
Mar 29, 2018, 08:26 pm Last Edit: Mar 29, 2018, 08:31 pm by ard_newbie
Could this damage the chip/USART bus? I don't see why setting USART3 in SPI mode would damage anything ?


BTW, I have never read anything about a LANC protocol. What is it used for ?

Edit: I found this projetc as a LANC protocol for arduino:
https://create.arduino.cc/projecthub/L-Rosen/serial-to-lanc-control-l-70f735?f=1

Psyco

"I don't see why setting USART3 in SPI mode would damage anything ?" I don't know how the not used clock line is terminated inside the pin package.


Many photo, film and video cameras use LANC, e.g. Blackmagic Design Cinema Camera.


I know that project (and quiete some more resources on the internet about LANC), but they all do bitbanging - which is ok, if the Arduino doesn't have much else to do. But my poor little ARM-chip will have so many (time critical) things to do, that I have to offload the LANC communication to an extra controller.

ard_newbie

#9
Mar 30, 2018, 05:34 am Last Edit: Mar 30, 2018, 05:44 am by ard_newbie
"I don't see why setting USART3 in SPI mode would damage anything ?" I don't know how the not used clock line is terminated inside the pin package.
Since PE16, namely SCK3 (SPI master clock output) is not present on the chip, there is only an internal clock for USART3 (which is good) and setting this internal clock obviousely do not damage anything. I did a sketch in which I initialize USART3 with its internal clock in SPI master mode, and the DUE works still nicely. This is true for other pins, e.g. PA31 is not available for the 144 pins chips (see page 618), however you can set or clear PA31 and nothing will be damaged in the chip.

...my poor little ARM-chip will have so many (time critical) things to do....
IMO it is REALLY difficult to achieve more than 95% of a Sam3x capacity unless you don't use it properly. The only example I can think of is a video streaming software, probably because no DMA had been used.

Psyco

Thanks for the quick test - really appreciate it (can't test with my board at the moment).


Oh, if I will get to 95% of that chips capacity I would be happy, but I really doubt it. Its more that I have a lot of time critical tasks running and want to make sure that non gets delayed. The rest will be filled with (simple) calculations and won't really tax the CPU.

Go Up