Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 13th October 2009, 06:53 PM   #1
Default SPI simulation help

I’ve been trying to learn assembly for the pic with MPLAB and simulating the code. Right now I am trying to understand SPI. Let’s assume the ports are set up correctly and we are trying to send a single byte out from the PIC to a slave.

Code:
		bcf		SS		;enable chip select output low
		movlw		0x07		;put in w
		movwf		SSPBUF		;put in SSPBUFD
		BANKSEL		SSPSTAT		;BANK1
Char1		btfss		SSPSTAT,BF	;data transfer complete?
		goto		Char1
		BANKSEL		SSPBUF		;BANK0
		movf		SSPBUF,W	;read sspbuf register
		bsf		SS		;disable chip select high

I would like to know if I understand what is going on correctly.

SS is set low to tell the slave data is about to transfer.
The byte is sent to sspbuf and then sent automatically out to the slave.
The code waits for the sspstat buffer full flag.

At this point the slave sends data back to the master. During simulation the code is in an infinite loop. I was stuck on this for two days and finally the light started to glow. Is the best way to simulate this is to use register injection and send a byte to sspbuf on demand to simulate what the slave would do in a real circuit?

The sspbuf is read and this clears the BF flag.
SS is set high to indicate the transfer is completed.

More SPI questions.

The datasheet for the slave device I’m looking at states, data is clocked out of the master in slave out (MISO) pin on the falling edge of the SCLK signal. Does this mean that you have to toggle SS after the MOSI data to initiate the MISO data? Do you check the BF flag after toggling SS?

I would like to be able to send multiple bytes to initiate a function on the slave, and read multiple bytes from the slave. Any hints on how to do this in assemble and simulate using MPLAB would be appreciated.
bobtm is offline  
Old 13th October 2009, 10:24 PM   #2
Default

Hi,

Perhaps this tutorial will help.

Have used it ok on hardware but never tried it on Sim.

http://ww1.microchip.com/downloads/en/devicedoc/spi.pdf
Wp100 is offline  
Old 13th October 2009, 10:55 PM   #3
Default

I found SPI to be a somewhat poorly described module in the documentation.
Honestly? Best thing is to hook up the SPI pins to other PIC pins, use ICD, and step through your questions and see what ends up in the SPI buffer reg and what signals show up on the pins when. If you use an external SPI clock, then there's no speed requirement on the code that pulses the pins tied to the SPI pins.

It does yield some definitive results if you've got very particular questions.
__________________
I thought what I'd do was I'd pretend I was one of those deaf-mutes.

Last edited by Oznog; 13th October 2009 at 10:57 PM.
Oznog is offline  
Old 14th October 2009, 04:39 PM   #4
Default

Wp100, Thanks for the comment and link. I've seen it and it is somewhat helpful

Oznog, Poorly described to say the least. I guess I will have to write some code and try it and educate myself on ICD.

Thanks again, Steve
bobtm is offline  
Reply

Tags
simulation, spi

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Simulation help Vikky General Electronics Chat 0 9th September 2009 06:03 AM
Spi aamirkhan Micro Controllers 1 9th June 2008 11:34 PM
Hardware SPI+SPI or SPI + Software I2C? William At MyBlueRoom Micro Controllers 2 19th August 2006 06:31 AM
about SPI! gas Micro Controllers 6 30th April 2005 05:07 AM
SPI Sherif Welsen Micro Controllers 6 7th September 2003 08:10 PM



All times are GMT. The time now is 10:46 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker