View previous topic :: View next topic |
Author |
Message |
Fabrici
Joined: 11 Feb 2013 Posts: 19 Location: Toulouse - France
|
FAST_IO and I2C interaction [solved] |
Posted: Thu Mar 14, 2013 9:31 am |
|
|
Hello,
I use PCD compiler V 4.141 with a DSPIC33EP256GP506. I encounter a very strange interraction between FAST_IO and I2C.
This program work, and I can see good signals on I2C connector with my oscilloscope :
Code: | #include <33EP256GP506.h>
#FUSES ICSP1 // ICD uses PGC1/PGD1 pins
#FUSES NOJTAG // JTAG disabled
#FUSES DEBUG // Debug mode for use with ICD
#fuses NOALTI2C1 // I2C1 mapped to SDA1/SCL1 pins
#fuses NOALTI2C2 // I2C2 mapped to SDA2/SCL2 pins
#FUSES NOWDT // No watchdog timer
#FUSES FRC_PLL //Internal Fast RC oscillator with PLL
#BUILD (STACK=0x1000:0x1200)
#USE delay (clock=50000000)
/*#USE FAST_IO(a)
#USE FAST_IO(b)
#USE FAST_IO(c)
#USE FAST_IO(d)
#USE FAST_IO(e)
#USE FAST_IO(f)
#USE FAST_IO(g)*/
#USE I2C(MASTER, I2C2, STREAM=I2CM2, FORCE_SW)
void main()
{
set_tris_a(0xE36F);
set_tris_b(0xDC1F);
set_tris_c(0xC030);
set_tris_d(0xFF9F);
set_tris_e(0x0FFF);
set_tris_f(0xFFFE);
set_tris_g(0xFCFF);
do
{
i2c_start(I2CM2);
i2c_write(I2CM2, 0x90); // adresse AD7745
i2c_write(I2CM2, 0xBF); // reset AD7745
i2c_stop(I2CM2);
delay_ms(1);
} while (TRUE);
} |
But the following one doesn't work : I2C SCL and SDA are just pulled up to 3.3V, and don't move at all. Only change with first program is the uncomment of #use fast_io instructions.
Code: | #include <33EP256GP506.h>
#FUSES ICSP1 // ICD uses PGC1/PGD1 pins
#FUSES NOJTAG // JTAG disabled
#FUSES DEBUG // Debug mode for use with ICD
#fuses NOALTI2C1 // I2C1 mapped to SDA1/SCL1 pins
#fuses NOALTI2C2 // I2C2 mapped to SDA2/SCL2 pins
#FUSES NOWDT // No watchdog timer
#FUSES FRC_PLL //Internal Fast RC oscillator with PLL
#BUILD (STACK=0x1000:0x1200)
#USE delay (clock=50000000)
#USE FAST_IO(a)
#USE FAST_IO(b)
#USE FAST_IO(c)
#USE FAST_IO(d)
#USE FAST_IO(e)
#USE FAST_IO(f)
#USE FAST_IO(g)
#USE I2C(MASTER, I2C2, STREAM=I2CM2, FORCE_SW)
void main()
{
set_tris_a(0xE36F);
set_tris_b(0xDC1F);
set_tris_c(0xC030);
set_tris_d(0xFF9F);
set_tris_e(0x0FFF);
set_tris_f(0xFFFE);
set_tris_g(0xFCFF);
do
{
i2c_start(I2CM2);
i2c_write(I2CM2, 0x90); // adresse AD7745
i2c_write(I2CM2, 0xBF); // reset AD7745
i2c_stop(I2CM2);
delay_ms(1);
} while (TRUE);
} |
Has someone encountered similar thing ? I would like to continue to use fast_io for my program. Is there a fix available ? May be a hint ?
Thanks in advance,
Best regards,
Fabrice
Last edited by Fabrici on Thu Mar 14, 2013 11:27 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Thu Mar 14, 2013 9:58 am |
|
|
maybe ....???
place the set_tris.... statements before the USE I2C.... statement ???
just a guess on my part....
hth
jay |
|
|
Fabrici
Joined: 11 Feb 2013 Posts: 19 Location: Toulouse - France
|
|
Posted: Thu Mar 14, 2013 10:03 am |
|
|
Thanks for your answer Jay,
I just tested it. It changes nothing that the USE I2C is placed before or after the set_tris ... statements.
Fabrice |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Thu Mar 14, 2013 10:49 am |
|
|
hmm..well it was a guess...
Other ideas...
1) Have you tried the I2C diagnostic program that PCMprogrammer put in the Code Library ?
2) Do you have the correct pullups on the I2C bus lines?
3) Have you tried other I2C peripherals? If so do they work?
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Thu Mar 14, 2013 10:55 am |
|
|
I'm sort of 'dubious' about the phraseology of your I2C setup. 'I2C2', says 'use the hardware port', but then you use FORCE_SW. I'd suspect the software setup requires the explicit pin names or it doesn't control the TRIS as it should. Worth trying either using hardware I2C, or explicitly giving the pin names.
Just an idea....
Best Wishes |
|
|
Fabrici
Joined: 11 Feb 2013 Posts: 19 Location: Toulouse - France
|
|
Posted: Thu Mar 14, 2013 11:23 am |
|
|
Bingo !!
Thanks Ttelmah. This setup worked perfectly:
Code: | #USE I2C(MASTER, I2C1, STREAM=I2CM1)
#USE I2C(MASTER, I2C2, STREAM=I2CM2) |
Effectively, it seems that software setup doesn't control the TRIS, and that it must be done manually. A warning at compile time will have been very helpful.
But in this case, it was best to use hardware, as you said. Thanks a lot.
Best regards,,
Fabrice |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Fri Mar 15, 2013 2:50 am |
|
|
I think you are fractionally missing the point.
What is unclear in the manual is that I2Cx, doesn't actually specify the pins, it says 'use the hardware port'....
The I2Cx nomenclature is effectively specifying 'FORCE_HW'. You are then overriding this with 'FORCE_SW', which leaves the software mode without a knowledge of what pins you actually want to use. A quick test, confirms that if you specify the pin names, the software mode works.
Best Wishes |
|
|
Fabrici
Joined: 11 Feb 2013 Posts: 19 Location: Toulouse - France
|
|
Posted: Fri Mar 15, 2013 4:03 am |
|
|
Thanks for your answer,
It was a fix I made with 4.140 to have my two I2C working. I agree that it was not a logical solution, but it solved my problems ... momentarily.
Then, I installed 4.141, and I2C2, stopped to work. I think that fixes have been made between the two versions.
Anyway, my configuration is now working as intented, and the I2C declaration is clear. A small regret though: the compiler would indicate that the directive "force_sw" implied a declaration of pin to use. A warning at compile time would have put me on the way.
Thanks a lot for your time,
Best regards,
Fabrice |
|
|
|