| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| FoxtrotMike 
 
 
 Joined: 31 May 2007
 Posts: 11
 
 
 
			    
 
 | 
			
				| Help: Trouble with SPI and MPLAB SIM... |  
				|  Posted: Tue Jul 22, 2008 2:16 pm |   |  
				| 
 |  
				| Hi: 
 I'm just starting with SPI, and i'm already stuck... I was trying to check the generated clock signal using MPLAB's Simulator Logic Analyzer. However, the program keeps running forever when using the spi_write() function. This is the code i've been trying so far:
 
 
  	  | Code: |  	  | #include <18F252.h>
 #fuses HS,NOWDT,NOPROTECT
 #use delay(clock=20000000)
 #use standard_io(B)
 #use standard_io(C)
 
 void main(void)
 {
 int i;
 
 setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_4|SPI_SS_DISABLED);
 
 for(i=0;i<10;i++)
 {
 output_high(PIN_B7);
 output_low(PIN_B6);
 delay_us(100);
 output_low(PIN_B7);
 output_high(PIN_B6);
 delay_us(100);
 }
 
 delay_cycles(1);   (*)
 
 spi_write(170);    (*)
 
 delay_cycles(1);   (*)
 
 }
 
 
 | 
 
 I used the "for" loop to test the Logic Analyzer, and it works just fine, it shows a 10 cycle pulse. But when trying to simulate a SPI write, MPLAB just says "Running"; of course, the waveform doesn't appear on the Logic Analyzer.
 
 (*) means I put a breakpoint in that line, and then used the MPLAB SIM "Run" button to test the code to that point. It works fine until it reaches the first checkpoint...
 
 By the way, I'm using PCH v4.038, and MPLAB 7.41. Thanks in advance for your help, i don't have a clue about what's wrong here...[/code]
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Jul 22, 2008 2:37 pm |   |  
				| 
 |  
				| It's polling the BF bit in SSPSTAT in a loop. 
 But read the Help file for MPSIM in MPLAB.
 Go to this menu tree in MPLAB:
 -Help
 -- Topics
 --- MPLAB SIM
 ---- Contents Tab
 ----- Limitations
 ------ General Limitations
 ------- PIC18F
 Eventually you get to this information:
 
  	  | Quote: |  	  | Depending on device, the following are not simulated:
 
 User ID memory.
 Programmable Switch-Mode Controller (PSMC).
 Brown-out detection (BOD) and low voltage detection (LVD).
 "Doze" power saving mode.
 Serial I/O (i.e., SSP including I2C and SPI). As a result, the SSPSTAT register has been made readable and writable.
 USB and CAN.
 Parallel Slave Port (PSP).
 D/A converter (DAC) and Op Amp (OPA).
 Quadrature Encoder Interface (QEI) of the Motion Feedback module.
 Code protection
 | 
 When using the simulator or the ICD2 hardware debugger, browse
 through the limitations.   There are a lot of them.
 |  | 
	
		|  | 
	
		| ckielstra 
 
 
 Joined: 18 Mar 2004
 Posts: 3680
 Location: The Netherlands
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Jul 22, 2008 3:30 pm |   |  
				| 
 |  
				| SPI_SS_DISABLED should only be set on a SPI slave device. On a master it creates an invalid setup combination. |  | 
	
		|  | 
	
		| FoxtrotMike 
 
 
 Joined: 31 May 2007
 Posts: 11
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Jul 22, 2008 3:33 pm |   |  
				| 
 |  
				| Thanks PCM programmer, quick and accurate as always... guess I'll have to program a PIC and watch the signal in an oscilloscope. Is there any other way to simulate SPI? 
 BTW, which version of MPLAB do you use? I looked up the help file, and could not find the paragraph you just showed me (I'm using MPLAB 7.41).
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Jul 22, 2008 3:46 pm |   |  
				| 
 |  
				| On this system I have 7.41.  Did you go to the "General Limitations" section in MPLAB SIM help ?   It's there for me.
 |  | 
	
		|  | 
	
		|  |