As a follow-up, I don't recall what chip you're using, but I recently found an errata on the PIC24HJ256GP610A about SPI. I have code that currently works on the non-A version, but does not work on the A version. Trying to chase that down... Harold > Hi all, > > MChip Support have offered this as a resolution. I need > a C to assembler translation in case I missed something > > ------------ > I wrote a small piece of code in C for SPI2 as follow: > UINT8 writeSPI2( UINT8 value ) > { > SPI2BUF =3D value; // write to buffer for TX > while(!SPI2STATbits.SPIRBF); // complete transfer wait > return SPI2BUF; // read the received value > and this is always working without any SPIROV issue. > ----------- > > Below is typical code I use to send a CMD to an SDHC card. In > it, SPIROV must be cleared right before the buffer read or it > simply doesn't work. Program will not get past the full buffer test > > How is MChip's code different ? I notice he uses SPI2 used for > some reason - the dsPIC I have has only SPI1. He didn't say > which PIC he's got his code running on > > If I execute this loop, which I think corresponds to the proposed > solution, > > t_loop: mov #cmd00,w0 ;0 + 0x40 > mov w0,SPI1BUF > btss SPI1STAT,#SPIRBF > bra $-2 > mov SPI1BUF,w2 > > mov #0xff,w0 > mov w0,SPI1BUF > btss SPI1STAT,#SPIRBF > bra $-2 > mov SPI1BUF,w2 > > bra t_loop > > all that results is 1/2 an iteration (attached). Flow halts at the very > first SPIRBF test. So his solution isn't appropriate for the dsPIC > I'm asking about. And I've already told him about that loop above. > He's just written in C and told me it works > > Please, if you can, consider the code carefully. I'm I wrong ? > > Joe > > Typical send CMD code > > mov #cmd00,w0 > call send_w0 > mov #0x00,w0 > call send_w0 > call send_w0 > call send_w0 > call send_w0 > mov #0x95,w0 > call send_w0 > > ;wait for '0x01' response > > more_00r: mov #0xff,w0 ;supply CLK, wait for response > call send_w0 ;with SDO high (FF data) > bclr SPI1STAT,#SPIROV ;must clear overflow flag > btss SPI1STAT,#SPIRBF ;test for full receive buffer > bra $-2 > mov SPI1BUF,w2 ;read buffer > mov #0x01,w1 ;wait for CMD0 '0x01' response > xor w1,w2,w1 > bra nz,more_00r > > ...more code > > send_w0: mov w0,SPI1BUF ;load data into SPI buffer > call usec50 ;wait at 368.64kHz > return-- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 FCC Rules Updated Daily at http://www.hallikainen.com - Advertising opportunities available! --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .