View previous topic :: View next topic |
Author |
Message |
dais
Joined: 03 May 2004 Posts: 11
|
simulator |
Posted: Wed May 05, 2004 11:06 am |
|
|
Hi,
I'm working on a I2c project. Here is code:
Code: |
void main()
{
output_float(I2C_SCL);
output_float(I2C_SDA);
i2c_start();
i2c_write(0x0f);
}
|
However When I run mplab6.5 simulator, Only trisc register changes, sspcon2 and sspstat doesn't change at all. The arrow stop at #useI2c.
Does it mean I can not simulate I2c ?
Thanks
Simin |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 05, 2004 11:27 am |
|
|
You are probably using software i2c.
To use hardware i2c:
1. Use a PIC that has a MSSP. (example: 16F877)
2. Specify the PIC pins that are dedicated to the MSSP
in your #use i2c statement. (example, pins C4 and C3 in the 16F877)
3. Add FORCE_HW to the end of your #use i2c statement.
Example:
#use i2c(Master, SDA=PIN_C4, SCL=PIN_C3, FORCE_HW) |
|
|
dais
Joined: 03 May 2004 Posts: 11
|
|
Posted: Wed May 05, 2004 2:11 pm |
|
|
Hi PCM,
Thanks for reply.
I use
#define I2C_SCL PIN_C3
#define I2C_SDA PIN_C4
#use i2c(MASTER, SDA = I2C_SCL, SCL = I2C_SDA, FORCE_HW)
Still not work
Is it Mplab 6.50 version matters or anything I did wrong?
Thanks
Simin |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 05, 2004 2:20 pm |
|
|
Quote: | #define I2C_SCL PIN_C3
#define I2C_SDA PIN_C4
#use i2c(MASTER, SDA = I2C_SCL, SCL = I2C_SDA, FORCE_HW) |
You are assigning the clock pin to the SDA signal, and the
data pin to the SCL signal. The compiler can only do hardware
i2c if you assign the pins correctly. So in the case above,
the compiler will ignore the Force_HW and just do software i2c. |
|
|
dais
Joined: 03 May 2004 Posts: 11
|
|
Posted: Wed May 05, 2004 3:01 pm |
|
|
PCM thanks, it works, sorry for the dummy mistakes, I shall check it carefully before I post. However, it stop at i2c_start() forever and never comes to i2c_write(). What's the problem?
Thanks
Simin |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 05, 2004 3:59 pm |
|
|
Quote: | However, it stop at i2c_start() forever and never comes to i2c_write(). What's the problem? |
If you click on View / Disassembly Listing, then click on that window,
then press F6 to reset the PIC, then press F8 to step through the
assembly code, you find that it's stuck in a loop, waiting for the
SEN bit of SSPCON2 to go low. It's waiting for the "start condition"
to finish.
So next, let's check the Help file:
In the MPLAB Help, under 18Fxxxx Limitations it says:
"Serial I/O (i.e., USART, I2C, SPI) is not simulated."
I'm using MPLAB vs. 6.42. So it appears that this version does not
simulate the MSSP in i2c mode. |
|
|
Guest
|
|
Posted: Wed May 05, 2004 4:11 pm |
|
|
Thanks for teaching me how to use debugger.
Simin |
|
|
|