sebmaster
Member level 1
- Joined
- Mar 9, 2008
- Messages
- 38
- Helped
- 2
- Reputation
- 4
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,719
Hello,
I have an AVR32 which needs to send 21 bit words (miniumum) to a CPLD.
I intend to use the SPI bus for this and have managed to set it all up, with a word size of 11 bit.
The idea is I take an integer, take the top 11 bits, shift it left 11 places, take the top 11 bits again, then send the two values in the reverse order I got them (the SPI sends data LSB first).
However my program is not working and I can't figure out why not, looking at the SPI output on a scope the LSBs (the first 21 bits sent) are always zero.
My test value is 0xFFFFFFFF so I should have to do a 16 bit shift before the value of the lower word starts dropping below its maximum surely?
Here is my code:
The uC I am using is an Atmel AVR32 UC3B. The architecture is big-endian.
Can anyone see any obvious mistakes?
I have an AVR32 which needs to send 21 bit words (miniumum) to a CPLD.
I intend to use the SPI bus for this and have managed to set it all up, with a word size of 11 bit.
The idea is I take an integer, take the top 11 bits, shift it left 11 places, take the top 11 bits again, then send the two values in the reverse order I got them (the SPI sends data LSB first).
However my program is not working and I can't figure out why not, looking at the SPI output on a scope the LSBs (the first 21 bits sent) are always zero.
My test value is 0xFFFFFFFF so I should have to do a 16 bit shift before the value of the lower word starts dropping below its maximum surely?
Here is my code:
Code:
spi_status_t response;
unsigned short word_high = (data & 0xFFE0);
data = data << 11; //shift left by 11 places to get next 11 bit word.
unsigned short word_low = (data & 0xFFE0);
response = spi_write( spi, word_low);
if( response == SPI_OK )
{ while( spi_writeEndCheck(spi) == 0){}
return spi_write( spi, word_high);
}
else
return response;
The uC I am using is an Atmel AVR32 UC3B. The architecture is big-endian.
Can anyone see any obvious mistakes?