Using SPI to Generate an Arbitrary Bitstream

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

I'm not near any hardware to test this in real life so am having to resort to the datasheet and memory.

 

I want to send a continuous bitstream out of an AVR at high speed. eg the LSB of byte 2 will immediately follow the MSB of byte 1 with no idle time on the data line or in the clock.

 

My recollection, and it seems to be backed up by the datasheet, is that because the SPI is only single buffered in the transmit direction then using the SPI peripheral won't work.

 

However if I use the USART in SPI mode then it will work based on this statement...

Quote:

A frame starts with the least or most significant data bit. Then the next data bits, up to a total of eight, are
succeeding, ending with the most or least significant bit accordingly. When a complete frame is transmitted, a
new frame can directly follow it, or the communication line can be set to an idle (high) state.

 

Have I remembered correctly?

 

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

Brian Fairchild wrote:

I'm not near any hardware to test this in real life so am having to resort to the datasheet and memory.

 

I want to send a continuous bitstream out of an AVR at high speed. eg the LSB of byte 2 will immediately follow the MSB of byte 1 with no idle time on the data line or in the clock.

 

My recollection, and it seems to be backed up by the datasheet, is that because the SPI is only single buffered in the transmit direction then using the SPI peripheral won't work.

 

However if I use the USART in SPI mode then it will work ...

 

Have I remembered correctly?

 

Indeed you have. I use this feature of the USART in SPI mode to send a Manchester-encoded bitstream using interrupts. Checked for glitches using a 'scope - none seen. (Project was a back-garden weather station - bitstream needs to be sent without blocking other tasks).

 

Steve

Maverick Embedded Technologies Ltd. Home of wAVR and Maven.

wAVR: WiFi AVR ISP/PDI/uPDI Programmer.

Maven: WiFi ARM Cortex-M Debugger/Programmer

https://www.maverick-embedded.co...

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

scdoubleu wrote:
I use this feature of the USART in SPI mode to send a Manchester-encoded bitstream using interrupts.
Brian Fairchild wrote:
bitstream out of an AVR at high speed.

 

While I agree that the buffered USART-as-SPI-master can make an unbroken bit stream, IMO first you need to define "high speed".  If an AVR8 I guess that if high-speed is about 1Mbps then an interrupt approach, ~12 cycle min overhead, might just work.  But at max rate?  I'd think not.

 

While "engineering is the art of making what you need out of what you have", isn't the described situation why DMA is included in some model lines?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.