Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Receive data via SPI

Status
Not open for further replies.

Sam Jelfs

New Member
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...

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
 

Attachments

  • 12.3 - read rxb.PNG
    12.3 - read rxb.PNG
    35.6 KB · Views: 185
HI SAM,

You are getting 0xFF i your MISO pin as your SDO pin is in High imnpedance state.

THe slave is not sending any data. If you want to confirm it. Just ground this pin, and you will get 0x00.

CHeck out the actual waveforms and try to figure out. I'm also stuck in a similar problem.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top