Hello all, just a quick question about SPI. (Bet you will all be glad when I get this project finished and stop asking silly questions )
I'm trying to read data from a buffer on a chip i'm using, reading from an MCP2515 to a 16F873A. Now i have the command for that I need to send to the MCP2515, as shown in the image below, and as far as I understand it, I have to send the command (B'10010010') and then send another byte of data to the chip, which it will ignore, so that I can get the data back from it.
the code i'm using is...
which should, as far as I know, send the command, and then move the received data into rx_data.
I have set SSPCON to 00100010 and SSPSTAT to 11000000, which corresponds to SPI mode 0,0, with data being sampled at the end of the output, and with clock as Fosc/64.
Now i know that there is valid data in the MCP2515 buffer, as the interrupt pin on it is set low, as it should be, and as the only other node is transmitting the data 11100111 that is what I should find at rx_data, but I'm not, I'm getting 11111111, is there a mistake anywhere that is obv to anyone? I'm only seeing the clock on the SCK pin for the periods of transmission, if I'm sampling after the data has been transmitted, should I not see clock output from the PIC for another 8 cycles?
cheers
Sam J
I'm trying to read data from a buffer on a chip i'm using, reading from an MCP2515 to a 16F873A. Now i have the command for that I need to send to the MCP2515, as shown in the image below, and as far as I understand it, I have to send the command (B'10010010') and then send another byte of data to the chip, which it will ignore, so that I can get the data back from it.
the code i'm using is...
Code:
load_rx_data bcf portc,cs
nop
movlw B'10010010'
movwf sspbuf
call spi_bf_full
movlw B'11001100'
movwf sspbuf
call spi_bf_full
movwf rx_data
bsf portc,cs
spi_bf_full
bsf status,rp0
bf_full btfss sspstat,0
goto bf_full
bcf status,rp0
movf sspbuf,0
return
which should, as far as I know, send the command, and then move the received data into rx_data.
I have set SSPCON to 00100010 and SSPSTAT to 11000000, which corresponds to SPI mode 0,0, with data being sampled at the end of the output, and with clock as Fosc/64.
Now i know that there is valid data in the MCP2515 buffer, as the interrupt pin on it is set low, as it should be, and as the only other node is transmitting the data 11100111 that is what I should find at rx_data, but I'm not, I'm getting 11111111, is there a mistake anywhere that is obv to anyone? I'm only seeing the clock on the SCK pin for the periods of transmission, if I'm sampling after the data has been transmitted, should I not see clock output from the PIC for another 8 cycles?
cheers
Sam J