Altera_Forum
Honored Contributor
12 years agoWeird sticky bit in SPI data
I'm using the Altera SPI Verlog code as a basis for an SPI / SD card interface for a Z80 based computer using a MAX3000A as the CPLD.
When I clock the SPI bus at a low data rate (around 430Khz or lower, as expected for SD card initialisation) it all works fine, however when I try and lower the clock divider to get a higher frequency after initialisation, anything above the 430Khz mark gives me a set bit 7 on the returned SPI data. At first the set high bit is intermittent at lower data rates, but when I clock it at the highest rate (~3.5Mhz) every byte returned has bit 7 set high. I've checked this with the scope, and when I see a value of 0x80 being returned to the processor, the MISO line is clearly low for the whole 8 clock pulses. And what's even weirder is if I invert the MISO line when storing in the shift register, the returned value is 0xFF to the processor and not 0x7F as you would expect if the data was being clocked in correctly from MISO. The only place the shift register is written is during the transceiving phase, so I cant see how it's corrupted, but equally I cant see how it isn't being corrupted given the results I'm getting. I've attached the source code for the SPI module, I hope someone can help me understand what's going on, as currently this makes no sense to me! I would also add the CPU clock and SPI clock are in different domains, so I've made some changes to make read / write only dependant on the RD / WR lines and not the clock as it was before.