Altera_Forum
Honored Contributor
19 years agoSPI Bus - Shifting Bits
Hi all,
Recent reader, first time poster... Here's the situation I am in. I am using the SPI bus of the Stratix II board to communicate with an external analog-digital converter (specifically the TLC0832). My test rig comprises a potentiometer to apply varying voltages to the Vin pin. And my test software is shown below (runs in an infinite while loop): IOWR_ALTERA_AVALON_SPI_STATUS(SPI_BASE, 0); IOWR_ALTERA_AVALON_SPI_SLAVE_SEL(SPI_BASE, 0xFFFF); while ((IORD_ALTERA_AVALON_SPI_STATUS(SPI_BASE) & ALTERA_AVALON_SPI_STATUS_TRDY_MSK) == 0) {}; IOWR_ALTERA_AVALON_SPI_TXDATA(SPI_BASE, "Arbitrary Data"); while ((IORD_ALTERA_AVALON_SPI_STATUS(SPI_BASE) & ALTERA_AVALON_SPI_STATUS_RRDY_MSK) == 0) {}; printf("%d\n", (IORD_ALTERA_AVALON_SPI_RXDATA(SPI_BASE) & 0x0FF)); usleep(1000000); Here's where things get funky. I set up 12-bit SPI data registers due to the ADC expecting 3 bits from the master, 1 bit empty and then 8 bits of actual data (hence why I mask off everything but the last 8 bits). Now, when I run the program and read out the integer values I receive, the values jump back and forth (seemingly randomly) between 2 numbers (at different voltages, the actual numbers are different, but the jumping is still there). Example: 7 7 56 7 56 56 7 etc... (No pattern intended) My three sets of samples showed these pairings of numbers: 7 & 56, 14 & 115, 29 & 238. The one common linkage is that if you do a bit-shift on the larger number by 3 places to the right, you'll end up with the smaller number. (The exception to this rule is 0V, which always shows a 0 integer) So, I was wondering whether anyone can think of what would cause a sporadic bit shift in the SPI bus? Any suggestions at all would be much appreciated. Thanks -Suresh