CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Help: Trouble with SPI and MPLAB SIM...

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
FoxtrotMike



Joined: 31 May 2007
Posts: 11

View user's profile Send private message

Help: Trouble with SPI and MPLAB SIM...
PostPosted: Tue Jul 22, 2008 2:16 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jul 22, 2008 2:37 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jul 22, 2008 3:30 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jul 22, 2008 3:33 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jul 22, 2008 3:46 pm     Reply with quote

On this system I have 7.41. Did you go to the "General Limitations"
section in MPLAB SIM help ? It's there for me.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group