SPI - Pascal Stang's library functions

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

Trying to load a DAC using Pascal's SPI library. Using WinAVR and a ATmega32.

***
. . .
spiSendByte(address);
spiSendByte(value);
DAC_SELECT(); // my enable line to load the DAC
. . .
***

Problem . . . unless I enable the SPI interrupt I can't get it to send out ANY data.
If I enable the SPI interrupt it will send out one byte skip over the next spiSendByte() and execute the DAC_SELECT() statement. (Global interrupts are enabled). N.B. the data (value) is actually sent out starting at the same time as the DAC_SELECT line goes high. DAC_SELECT should be enabled AFTER the all the data has been sent out. So, the DAC never "sees" this 2nd byte!

His code spi code appears to be able to send multiple bytes, in that there is a spiTransferComplete flag that manages the whole operation.

I suspect there is something fundamental I am not doing correctly as I also have problems running his timer functions without interrupts.

Normally all most of my S/W problems are with interrupt routines, but now it seems the other way!

Really appreciate it if someone could suggest where I am going wrong.

Thank you

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

More on the issue with missing the 2nd byte. If I put a small delay BEFORE the DAC_SELECT() statement I can get both bytes out. It appears that the 2nd time spiSendByte() is called it doesn't wait for the spiTransferComplete flag.

Is there something else I need to reset after each spiSendByte()?