1
\$\begingroup\$

I am very new to AVR and even for coding of micro-controllers. I wanted to shift out 32 bit data on SPI from a Atmega16 to a 32 bit shift register. The shift register in not an SPI compatible device. But still hope to use to get the fast transmission.

Since the AVR is having only 8 bit data register, only one byte of data can be written on it. So I need to shift our 32 bits of data. I am able to do the same like making SS# low->load first byte of data->wait till transmission complete->make SS# to high to latch the data. I am doing it four 4 times and getting the 32 bit output. But the issue here is the clock is not continuous, for each byte there is a delay between the clock burst. In this this case the external shift register will not get the 32 bit continuously since for every byte I am doing the SS# low and high. I need to get the complete data packet continuously with out any break. I am digging further into this to resolve.

It would be helpful for me in the meantime if someone can share any idea.

Regards, Prabhu

\$\endgroup\$
  • 1
    \$\begingroup\$ Please add any relevant snippet of code, no crystal balls lying around here. Help us help you. \$\endgroup\$ – Vladimir Cravero Sep 8 '14 at 7:49
1
\$\begingroup\$

Continuous transactions longer than 8 bits are not possible on ATMega16. You have to poll for SPIF and then load new value. On other MCUs that have double buffered data register, it is possible to reload the data register before it is emptied.

There is no need to assert SS# between words. From SPI's static point of view, in modes 1 or 3, sending 8*4 bits is equivalent to sending 1*32 bits even when it happens seconds apart.

\$\endgroup\$
0
\$\begingroup\$

You could keep the current desired state of the shift register in a single uint32_t variable. Each time when there's the need to change the shift register's output you modify the variable accordingly and then send the whole 32bits; that is, always send all 32bits, even if only one bit changes. This way, you will have a consistent representation of the state of the shift register in memory and don't have to worry about which byte/bit to send when.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.