|
|
View previous topic :: View next topic |
Author |
Message |
BeeElectronic
Joined: 19 Jul 2017 Posts: 27
|
PIC24EP and I2C issue |
Posted: Wed Jul 19, 2017 4:05 am |
|
|
Hello,
I try to implement a communication between a PIC24EP256GU810 and a 24AA512 EERPOM with a 400kHz I2C bus but I have a few issues.
Compiler:
- 5.073
Hardware:
- SDA2 (PIN_F4) to SDA pin of the EEPROM
- SCL2 (PIN_F5) to SCL pin of the EEPROM
- A 1.5kOhms pullup resistor to 3.3VDC on SDA and SCL
- WP to GND
- A0, A1, A2 to GND
Fuses:
Code: |
#include <24EP256GU810.h>
#device ICSP=3
#use delay(internal=47905000,restart_wdt)
#FUSES WDT //Watch Dog Timer
#FUSES WPRES32 //Watch Dog Timer PreScalar 1:32
#FUSES WPOSTS11 //Watch Dog Timer PostScalar 1:1024
#FUSES OSCIO //OSC2 is general purpose output
#FUSES NOWRT //Program memory not write protected
#FUSES NOPROTECT //Code not protected from reading
#FUSES GSSK //General Segment Key bits, use if using either WRT or PROTECT fuses
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES PLLWAIT //Clock switch to PLL will wait until the PLL lock signal is valid
#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES PUT32 //Power On Reset Timer value 32ms
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOALTI2C1 //I2C1 mapped to SDA1/SCL1 pins
#FUSES NOALTI2C2 //I2C2 mapped to SDA2/SCL2 pins
#FUSES RESET_PRIMARY //Device will reset to Primary Flash Reset location
#FUSES NOJTAG //JTAG disabled
#FUSES NOAWRT //Auxiliary program memory is not write-protected
#FUSES NOAPROTECT //Auxiliary program memory is not code-protected
#FUSES APLK //Auxiliary Segment Key bits, use if using either AWRT or APROTECT fuses
#use i2c(MASTER, I2C2, FAST, RESTART_WDT, stream=BUS_I2C)
#endif
|
Main:
Code: |
void main()
{
while(TRUE)
{
i2c_start(BUS_I2C);
i2c_write(BUS_I2C, 0);
i2c_stop(BUS_I2C);
}
}
|
When I put the scope on the SDA and SCL pin nothing appears (no communication at all).
It's the same if I use this definition:
Code: |
#define EEPARA_SCL PIN_F5 // SCL
#define EEPARA_SDA PIN_F4 // SDA
#use i2c(MASTER, SCL=EEPARA_SCL, SDA=EEPARA_SDA, FAST, RESTART_WDT, stream=BUS_I2C)
|
But if I reverse the SDA and SCL pin or if I use another pin for SDA or SCL the PIC start the communication.
Code: |
#define EEPARA_SCL PIN_F4 // SCL
#define EEPARA_SDA PIN_F5 // SDA
// OR
#define EEPARA_SCL PIN_F5 // SCL
#define EEPARA_SDA PIN_F3 // SDA
// OR
#define EEPARA_SCL PIN_F3 // SCL
#define EEPARA_SDA PIN_F4 // SDA
#use i2c(MASTER, SCL=EEPARA_SCL, SDA=EEPARA_SDA, FAST, RESTART_WDT, stream=BUS_I2C)
|
On the device editor I change the I2C-2 pin from F5/A2, F4/A3 to F5/F4. MASTER and SLAVE = TRUE. And still this issue.
I think I forgot something but I don't know what. Do you have an idea? |
|
|
BeeElectronic
Joined: 19 Jul 2017 Posts: 27
|
|
Posted: Wed Jul 19, 2017 4:45 am |
|
|
If I put
Code: |
#use i2c(MASTER, I2C2, FAST, RESTART_WDT, stream=BUS_I2C, FORCE_SW)
|
The bus work well... so strange... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Wed Jul 19, 2017 5:06 am |
|
|
I had a very, very quick look at the PICs datasheet and it appears that F5 is the I2C #2 clock, F4 is the I2C #2 data lines.
I suspect in your various tries you're NOT using the internal I2C peripheral, rather a compiler generated I2C driver. The listing would confirm/deny this. Also look in the manual for the correct 'use I2C (....options...) and syntax.
The other problem for me is the WDT. Disable it...NOT required...maybe useful WHEN your complete, 100 % operational program is 'up and running', but until then get rid of it. It'll cause you a lot of headaches.
Also whenever using I2C peripherals, download/compile/run PCM P's I2C scanner program from the 'code library' before cutting your own code ! It'll find all I2C devices on the bus and report them !! It works great and wil confirm your hardware is operational, saving you hours...or days of debugging time.
The other possible problem is this PIC has 144 pins !! It'd be real easy to 'solder bridge' a pin or two...so best to ring out every pin...
Jay |
|
|
BeeElectronic
Joined: 19 Jul 2017 Posts: 27
|
|
Posted: Wed Jul 19, 2017 7:00 am |
|
|
Thank you for your reply
Quote: |
I had a very, very quick look at the PICs datasheet and it appears that F5 is the I2C #2 clock, F4 is the I2C #2 data lines.
|
Yes , it's true
Quote: |
I suspect in your various tries you're NOT using the internal I2C peripheral, rather a compiler generated I2C driver. The listing would confirm/deny this. Also look in the manual for the correct 'use I2C (....options...) and syntax.
|
Yes I think so. I probably miss something.
Quote: |
Also whenever using I2C peripherals, download/compile/run PCM P's I2C scanner program from the 'code library' before cutting your own code ! It'll find all I2C devices on the bus and report them !! It works great and wil confirm your hardware is operational, saving you hours...or days of debugging time.
|
With this #use
Code: |
#use i2c(MASTER, I2C2, FAST, RESTART_WDT, stream=BUS_I2C, FORCE_SW)
|
The I2C scanner code in debug mode return:
- Count = 1
- i = 0xA0
And my I2C communication work perfectly. I write "123" in the EEPROM at the address 0 and when I read the address 0 I2C_read() return me 123.
But if I use this #use
Code: |
#use i2c(MASTER, I2C2, FAST, RESTART_WDT, stream=BUS_I2C)
|
The I2C scanner code return nothing. And my I2C bus don't work. |
|
|
BeeElectronic
Joined: 19 Jul 2017 Posts: 27
|
|
Posted: Wed Jul 19, 2017 7:03 am |
|
|
With FORCE_SW
Code: |
CCS PCD C Compiler, Version 5.073, xxxxx 19-juil.-17 14:59
Filename: C:\Users\BE1\Desktop\Programmes - Copie\main.lst
ROM used: 1424 bytes (1%)
Largest free fragment is 65536
RAM used: 116 (0%) at main() level
119 (0%) worst case
Stack used: 24 locations
Stack size: 112
*
00000: GOTO 48E
.................... #include <main.h>
.................... #ifndef MAIN_H
.................... #define MAIN_H
....................
.................... #include <24EP256GU810.h>
.................... //////////// Standard Header file for the PIC24EP256GU810 device ////////////////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996, 2014 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... #device PIC24EP256GU810
*
00200: CLR 54
00202: MOV #20C,W3
00204: ADD W3,W0,W0
00206: TBLRDL.B[W0],W0L
00208: CLR.B 1
0020A: RETURN
0020C: DATA 0A,0D,00
0020E: DATA 53,74,00
00210: DATA 61,72,00
00212: DATA 74,3A,00
00214: DATA 0A,0D,00
00216: DATA 00,00,00
00218: CLR 54
0021A: MOV #224,W3
0021C: ADD W3,W0,W0
0021E: TBLRDL.B[W0],W0L
00220: CLR.B 1
00222: RETURN
00224: DATA 41,43,00
00226: DATA 4B,20,00
00228: DATA 61,64,00
0022A: DATA 64,72,00
0022C: DATA 3A,20,00
0022E: DATA 25,58,00
00230: DATA 0A,0D,00
00232: DATA 00,00,00
00234: CLR 54
00236: MOV #240,W3
00238: ADD W3,W0,W0
0023A: TBLRDL.B[W0],W0L
0023C: CLR.B 1
0023E: RETURN
00240: DATA 0A,0D,00
00242: DATA 4E,6F,00
00244: DATA 74,68,00
00246: DATA 69,6E,00
00248: DATA 67,20,00
0024A: DATA 46,6F,00
0024C: DATA 75,6E,00
0024E: DATA 64,00,00
00250: CLR 54
00252: MOV #25C,W3
00254: ADD W3,W0,W0
00256: TBLRDL.B[W0],W0L
00258: CLR.B 1
0025A: RETURN
0025C: DATA 0A,0D,00
0025E: DATA 4E,75,00
00260: DATA 6D,62,00
00262: DATA 65,72,00
00264: DATA 20,6F,00
00266: DATA 66,20,00
00268: DATA 69,32,00
0026A: DATA 63,20,00
0026C: DATA 63,68,00
0026E: DATA 69,70,00
00270: DATA 73,20,00
00272: DATA 66,6F,00
00274: DATA 75,6E,00
00276: DATA 64,3A,00
00278: DATA 20,25,00
0027A: DATA 75,00,00
*
00374: MOV W0,W3
00376: SWAP W1
00378: MOV.B #5,W4L
0037A: DEC.B 0003
0037C: DEC.B 0008
0037E: BRA Z,3B2
00380: MOV W3,W0
00382: SL W3,#4,W3
00384: LSR W0,#C,W0
00386: AND #F,W0
00388: BRA NZ,392
0038A: CP.B W4L,#1
0038C: BRA Z,392
0038E: BTSS.B 3.7
00390: BRA 37A
00392: ADD #30,W0
00394: MOV #3A,W2
00396: CP W0,W2
00398: BRA NC,39C
0039A: ADD.B 2,W0L
0039C: MOV W1,[W15++]
0039E: MOV W3,[W15++]
003A0: MOV W4,[W15++]
003A2: MOV.B W0L,1060
003A4: CALL 27C
003A8: MOV [--W15],W4
003AA: MOV [--W15],W3
003AC: MOV [--W15],W1
003AE: BSET.B 3.7
003B0: BRA 37A
003B2: RETURN
003B4: MOV W5,[W15++]
003B6: MOV #C,W5
003B8: REPEAT #3
003BA: MOV [W5++],[W15++]
003BC: MOV W0,W7
003BE: MOV W4,W9
003C0: BCLR W4.F
003C2: CP0 W4
003C4: BRA NZ,3D2
003C6: BTSC W9.F
003C8: BRA 3CE
003CA: MOV #0,W5
003CC: BRA 3FC
003CE: MOV #0,W5
003D0: BRA 3FC
003D2: SUB.B W4L,#6,W5L
003D4: BRA NC,3FA
003D6: MOV #30,W0
003D8: BTSS W9.F
003DA: MOV #20,W0
003DC: MOV W0,[W15++]
003DE: MOV W1,[W15++]
003E0: MOV.D W2,[W15++]
003E2: MOV W4,[W15++]
003E4: MOV.B W0L,1060
003E6: CALL 27C
003EA: MOV [--W15],W4
003EC: MOV.D [--W15],W2
003EE: MOV [--W15],W1
003F0: MOV [--W15],W0
003F2: DEC W5,W5
003F4: BRA NN,3DC
003F6: MOV #5,W5
003F8: BRA 3FC
003FA: MOV W4,W5
003FC: MOV #6,W4
003FE: BSET W5.E
00400: BTSC W9.F
00402: BSET W5.F
00404: MOV #2710,W8
00406: REPEAT #11
00408: DIV.U W7,W8
0040A: CALL 44A
0040E: MOV W1,W7
00410: MOV #3E8,W8
00412: REPEAT #11
00414: DIV.U W7,W8
00416: CALL 44A
0041A: MOV W1,W7
0041C: MOV #64,W8
0041E: REPEAT #11
00420: DIV.U W7,W8
00422: CALL 44A
00426: MOV W1,W7
00428: MOV #A,W8
0042A: REPEAT #11
0042C: DIV.U W7,W8
0042E: CALL 44A
00432: MOV #30,W0
00434: ADD.B W1L,W0L,W0L
00436: MOV W1,[W15++]
00438: MOV.D W2,[W15++]
0043A: MOV W4,[W15++]
0043C: MOV.B W0L,1060
0043E: CALL 27C
00442: MOV [--W15],W4
00444: MOV.D [--W15],W2
00446: MOV [--W15],W1
00448: BRA 484
0044A: MOV #30,W6
0044C: CP0 W0
0044E: BRA NZ,46C
00450: BTSS W5.E
00452: BRA 46E
00454: DEC W4,W4
00456: CP.B W4L,W5L
00458: BRA Z,45E
0045A: BTSC.B 42.0
0045C: RETURN
0045E: CP0 W0
00460: BRA NZ,46C
00462: BTSS W5.E
00464: BRA 46E
00466: BTSS W5.F
00468: MOV #20,W6
0046A: BRA 46E
0046C: BCLR W5.E
0046E: ADD.B W6L,W0L,W0L
00470: MOV W1,[W15++]
00472: MOV W2,[W15++]
00474: MOV W4,[W15++]
00476: MOV.B W0L,1060
00478: CALL 27C
0047C: MOV [--W15],W4
0047E: MOV [--W15],W2
00480: MOV [--W15],W1
00482: RETURN
00484: MOV #12,W5
00486: REPEAT #3
00488: MOV [--W15],[W5--]
0048A: MOV [--W15],W5
0048C: RETURN
....................
.................... #list
....................
.................... #device ADC=12
.................... #device ICSP=3
.................... #use delay(internal=47905000,restart_wdt)
*
002A0: CP0 W0
002A2: BTSC.B 42.1
002A4: BRA 2B2
002A6: REPEAT #1D8B
002A8: CLRWDT
002AA: REPEAT #3FFE
002AC: CLRWDT
002AE: DEC W0,W0
002B0: BRA NZ,2A6
002B2: RETURN
....................
.................... #FUSES WDT //Watch Dog Timer
.................... #FUSES WPRES32 //Watch Dog Timer PreScalar 1:32
.................... #FUSES WPOSTS11 //Watch Dog Timer PostScalar 1:1024
.................... #FUSES OSCIO //OSC2 is general purpose output
.................... #FUSES NOWRT //Program memory not write protected
.................... #FUSES NOPROTECT //Code not protected from reading
.................... #FUSES GSSK //General Segment Key bits, use if using either WRT or PROTECT fuses
.................... #FUSES IESO //Internal External Switch Over mode enabled
.................... #FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
.................... #FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
.................... #FUSES PLLWAIT //Clock switch to PLL will wait until the PLL lock signal is valid
.................... #FUSES WINDIS //Watch Dog Timer in non-Window mode
.................... #FUSES PUT32 //Power On Reset Timer value 32ms
.................... #FUSES BROWNOUT //Reset when brownout detected
.................... #FUSES NOALTI2C1 //I2C1 mapped to SDA1/SCL1 pins
.................... #FUSES NOALTI2C2 //I2C2 mapped to SDA2/SCL2 pins
.................... #FUSES RESET_PRIMARY //Device will reset to Primary Flash Reset location
.................... #FUSES JTAG //JTAG
.................... #FUSES NOAWRT //Auxiliary program memory is not write-protected
.................... #FUSES NOAPROTECT //Auxiliary program memory is not code-protected
.................... #FUSES APLK //Auxiliary Segment Key bits, use if using either AWRT or APROTECT fuses
....................
.................... #use i2c(MASTER, I2C2, FAST, RESTART_WDT, stream=BUS_I2C, FORCE_SW)
*
002BA: MOV #8,W2
002BC: CLRWDT
002BE: REPEAT #10
002C0: CLRWDT
002C2: BCLR.B E54.5
002C4: BCLR.B E50.5
002C6: CLRWDT
002C8: REPEAT #12
002CA: CLRWDT
002CC: RLC.B W1L,W1L
002CE: BCLR.B E54.4
002D0: BTSC.B 42.0
002D2: BSET.B E50.4
002D4: BTSS.B 42.0
002D6: BCLR.B E50.4
002D8: BSET.B E50.5
002DA: BTSS.B E52.5
002DC: BRA 2DA
002DE: DEC W2,W2
002E0: BRA NZ,2BC
002E2: CLRWDT
002E4: REPEAT #10
002E6: CLRWDT
002E8: BCLR.B E54.5
002EA: BCLR.B E50.5
002EC: NOP
002EE: BSET.B E50.4
002F0: CLRWDT
002F2: REPEAT #12
002F4: CLRWDT
002F6: CLRWDT
002F8: REPEAT #12
002FA: CLRWDT
002FC: BSET.B E50.5
002FE: BTSS.B E52.5
00300: BRA 2FE
00302: CLRWDT
00304: REPEAT #12
00306: CLRWDT
00308: MOV #0,W0
0030A: BTSC.B E52.4
0030C: BSET W0.0
0030E: BCLR.B E54.5
00310: BCLR.B E50.5
00312: BCLR.B E54.4
00314: BCLR.B E50.4
00316: RETURN
.................... #use rs232(xmit=PIN_C1, rcv=PIN_C2, baud=9600, errors)
*
0027C: BCLR.B E20.1
0027E: BCLR.B E24.1
00280: MOV #8,W3
00282: REPEAT #9BB
00284: CLRWDT
00286: RRC.B 1060
00288: BTSC.B 42.0
0028A: BSET.B E24.1
0028C: BTSS.B 42.0
0028E: BCLR.B E24.1
00290: REPEAT #9B6
00292: CLRWDT
00294: DEC W3,W3
00296: BRA NZ,286
00298: BSET.B E24.1
0029A: REPEAT #9BD
0029C: CLRWDT
0029E: RETURN
....................
.................... #endif
|
|
|
|
BeeElectronic
Joined: 19 Jul 2017 Posts: 27
|
|
Posted: Wed Jul 19, 2017 7:05 am |
|
|
With FORCE_SW
Code: |
CCS PCD C Compiler, Version 5.073, xxxxx 19-juil.-17 14:59
Filename: C:\Users\BE1\Desktop\Programmes - Copie\main.lst
ROM used: 1424 bytes (1%)
Largest free fragment is 65536
RAM used: 116 (0%) at main() level
119 (0%) worst case
Stack used: 24 locations
Stack size: 112
*
00000: GOTO 48E
.................... #include <main.h>
.................... #ifndef MAIN_H
.................... #define MAIN_H
....................
.................... #include <24EP256GU810.h>
.................... //////////// Standard Header file for the PIC24EP256GU810 device ////////////////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996, 2014 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... #device PIC24EP256GU810
*
00200: CLR 54
00202: MOV #20C,W3
00204: ADD W3,W0,W0
00206: TBLRDL.B[W0],W0L
00208: CLR.B 1
0020A: RETURN
0020C: DATA 0A,0D,00
0020E: DATA 53,74,00
00210: DATA 61,72,00
00212: DATA 74,3A,00
00214: DATA 0A,0D,00
00216: DATA 00,00,00
00218: CLR 54
0021A: MOV #224,W3
0021C: ADD W3,W0,W0
0021E: TBLRDL.B[W0],W0L
00220: CLR.B 1
00222: RETURN
00224: DATA 41,43,00
00226: DATA 4B,20,00
00228: DATA 61,64,00
0022A: DATA 64,72,00
0022C: DATA 3A,20,00
0022E: DATA 25,58,00
00230: DATA 0A,0D,00
00232: DATA 00,00,00
00234: CLR 54
00236: MOV #240,W3
00238: ADD W3,W0,W0
0023A: TBLRDL.B[W0],W0L
0023C: CLR.B 1
0023E: RETURN
00240: DATA 0A,0D,00
00242: DATA 4E,6F,00
00244: DATA 74,68,00
00246: DATA 69,6E,00
00248: DATA 67,20,00
0024A: DATA 46,6F,00
0024C: DATA 75,6E,00
0024E: DATA 64,00,00
00250: CLR 54
00252: MOV #25C,W3
00254: ADD W3,W0,W0
00256: TBLRDL.B[W0],W0L
00258: CLR.B 1
0025A: RETURN
0025C: DATA 0A,0D,00
0025E: DATA 4E,75,00
00260: DATA 6D,62,00
00262: DATA 65,72,00
00264: DATA 20,6F,00
00266: DATA 66,20,00
00268: DATA 69,32,00
0026A: DATA 63,20,00
0026C: DATA 63,68,00
0026E: DATA 69,70,00
00270: DATA 73,20,00
00272: DATA 66,6F,00
00274: DATA 75,6E,00
00276: DATA 64,3A,00
00278: DATA 20,25,00
0027A: DATA 75,00,00
*
00374: MOV W0,W3
00376: SWAP W1
00378: MOV.B #5,W4L
0037A: DEC.B 0003
0037C: DEC.B 0008
0037E: BRA Z,3B2
00380: MOV W3,W0
00382: SL W3,#4,W3
00384: LSR W0,#C,W0
00386: AND #F,W0
00388: BRA NZ,392
0038A: CP.B W4L,#1
0038C: BRA Z,392
0038E: BTSS.B 3.7
00390: BRA 37A
00392: ADD #30,W0
00394: MOV #3A,W2
00396: CP W0,W2
00398: BRA NC,39C
0039A: ADD.B 2,W0L
0039C: MOV W1,[W15++]
0039E: MOV W3,[W15++]
003A0: MOV W4,[W15++]
003A2: MOV.B W0L,1060
003A4: CALL 27C
003A8: MOV [--W15],W4
003AA: MOV [--W15],W3
003AC: MOV [--W15],W1
003AE: BSET.B 3.7
003B0: BRA 37A
003B2: RETURN
003B4: MOV W5,[W15++]
003B6: MOV #C,W5
003B8: REPEAT #3
003BA: MOV [W5++],[W15++]
003BC: MOV W0,W7
003BE: MOV W4,W9
003C0: BCLR W4.F
003C2: CP0 W4
003C4: BRA NZ,3D2
003C6: BTSC W9.F
003C8: BRA 3CE
003CA: MOV #0,W5
003CC: BRA 3FC
003CE: MOV #0,W5
003D0: BRA 3FC
003D2: SUB.B W4L,#6,W5L
003D4: BRA NC,3FA
003D6: MOV #30,W0
003D8: BTSS W9.F
003DA: MOV #20,W0
003DC: MOV W0,[W15++]
003DE: MOV W1,[W15++]
003E0: MOV.D W2,[W15++]
003E2: MOV W4,[W15++]
003E4: MOV.B W0L,1060
003E6: CALL 27C
003EA: MOV [--W15],W4
003EC: MOV.D [--W15],W2
003EE: MOV [--W15],W1
003F0: MOV [--W15],W0
003F2: DEC W5,W5
003F4: BRA NN,3DC
003F6: MOV #5,W5
003F8: BRA 3FC
003FA: MOV W4,W5
003FC: MOV #6,W4
003FE: BSET W5.E
00400: BTSC W9.F
00402: BSET W5.F
00404: MOV #2710,W8
00406: REPEAT #11
00408: DIV.U W7,W8
0040A: CALL 44A
0040E: MOV W1,W7
00410: MOV #3E8,W8
00412: REPEAT #11
00414: DIV.U W7,W8
00416: CALL 44A
0041A: MOV W1,W7
0041C: MOV #64,W8
0041E: REPEAT #11
00420: DIV.U W7,W8
00422: CALL 44A
00426: MOV W1,W7
00428: MOV #A,W8
0042A: REPEAT #11
0042C: DIV.U W7,W8
0042E: CALL 44A
00432: MOV #30,W0
00434: ADD.B W1L,W0L,W0L
00436: MOV W1,[W15++]
00438: MOV.D W2,[W15++]
0043A: MOV W4,[W15++]
0043C: MOV.B W0L,1060
0043E: CALL 27C
00442: MOV [--W15],W4
00444: MOV.D [--W15],W2
00446: MOV [--W15],W1
00448: BRA 484
0044A: MOV #30,W6
0044C: CP0 W0
0044E: BRA NZ,46C
00450: BTSS W5.E
00452: BRA 46E
00454: DEC W4,W4
00456: CP.B W4L,W5L
00458: BRA Z,45E
0045A: BTSC.B 42.0
0045C: RETURN
0045E: CP0 W0
00460: BRA NZ,46C
00462: BTSS W5.E
00464: BRA 46E
00466: BTSS W5.F
00468: MOV #20,W6
0046A: BRA 46E
0046C: BCLR W5.E
0046E: ADD.B W6L,W0L,W0L
00470: MOV W1,[W15++]
00472: MOV W2,[W15++]
00474: MOV W4,[W15++]
00476: MOV.B W0L,1060
00478: CALL 27C
0047C: MOV [--W15],W4
0047E: MOV [--W15],W2
00480: MOV [--W15],W1
00482: RETURN
00484: MOV #12,W5
00486: REPEAT #3
00488: MOV [--W15],[W5--]
0048A: MOV [--W15],W5
0048C: RETURN
....................
.................... #list
....................
.................... #device ADC=12
.................... #device ICSP=3
.................... #use delay(internal=47905000,restart_wdt)
*
002A0: CP0 W0
002A2: BTSC.B 42.1
002A4: BRA 2B2
002A6: REPEAT #1D8B
002A8: CLRWDT
002AA: REPEAT #3FFE
002AC: CLRWDT
002AE: DEC W0,W0
002B0: BRA NZ,2A6
002B2: RETURN
....................
.................... #FUSES WDT //Watch Dog Timer
.................... #FUSES WPRES32 //Watch Dog Timer PreScalar 1:32
.................... #FUSES WPOSTS11 //Watch Dog Timer PostScalar 1:1024
.................... #FUSES OSCIO //OSC2 is general purpose output
.................... #FUSES NOWRT //Program memory not write protected
.................... #FUSES NOPROTECT //Code not protected from reading
.................... #FUSES GSSK //General Segment Key bits, use if using either WRT or PROTECT fuses
.................... #FUSES IESO //Internal External Switch Over mode enabled
.................... #FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
.................... #FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
.................... #FUSES PLLWAIT //Clock switch to PLL will wait until the PLL lock signal is valid
.................... #FUSES WINDIS //Watch Dog Timer in non-Window mode
.................... #FUSES PUT32 //Power On Reset Timer value 32ms
.................... #FUSES BROWNOUT //Reset when brownout detected
.................... #FUSES NOALTI2C1 //I2C1 mapped to SDA1/SCL1 pins
.................... #FUSES NOALTI2C2 //I2C2 mapped to SDA2/SCL2 pins
.................... #FUSES RESET_PRIMARY //Device will reset to Primary Flash Reset location
.................... #FUSES JTAG //JTAG
.................... #FUSES NOAWRT //Auxiliary program memory is not write-protected
.................... #FUSES NOAPROTECT //Auxiliary program memory is not code-protected
.................... #FUSES APLK //Auxiliary Segment Key bits, use if using either AWRT or APROTECT fuses
....................
.................... #use i2c(MASTER, I2C2, FAST, RESTART_WDT, stream=BUS_I2C, FORCE_SW)
*
002BA: MOV #8,W2
002BC: CLRWDT
002BE: REPEAT #10
002C0: CLRWDT
002C2: BCLR.B E54.5
002C4: BCLR.B E50.5
002C6: CLRWDT
002C8: REPEAT #12
002CA: CLRWDT
002CC: RLC.B W1L,W1L
002CE: BCLR.B E54.4
002D0: BTSC.B 42.0
002D2: BSET.B E50.4
002D4: BTSS.B 42.0
002D6: BCLR.B E50.4
002D8: BSET.B E50.5
002DA: BTSS.B E52.5
002DC: BRA 2DA
002DE: DEC W2,W2
002E0: BRA NZ,2BC
002E2: CLRWDT
002E4: REPEAT #10
002E6: CLRWDT
002E8: BCLR.B E54.5
002EA: BCLR.B E50.5
002EC: NOP
002EE: BSET.B E50.4
002F0: CLRWDT
002F2: REPEAT #12
002F4: CLRWDT
002F6: CLRWDT
002F8: REPEAT #12
002FA: CLRWDT
002FC: BSET.B E50.5
002FE: BTSS.B E52.5
00300: BRA 2FE
00302: CLRWDT
00304: REPEAT #12
00306: CLRWDT
00308: MOV #0,W0
0030A: BTSC.B E52.4
0030C: BSET W0.0
0030E: BCLR.B E54.5
00310: BCLR.B E50.5
00312: BCLR.B E54.4
00314: BCLR.B E50.4
00316: RETURN
.................... #use rs232(xmit=PIN_C1, rcv=PIN_C2, baud=9600, errors)
*
0027C: BCLR.B E20.1
0027E: BCLR.B E24.1
00280: MOV #8,W3
00282: REPEAT #9BB
00284: CLRWDT
00286: RRC.B 1060
00288: BTSC.B 42.0
0028A: BSET.B E24.1
0028C: BTSS.B 42.0
0028E: BCLR.B E24.1
00290: REPEAT #9B6
00292: CLRWDT
00294: DEC W3,W3
00296: BRA NZ,286
00298: BSET.B E24.1
0029A: REPEAT #9BD
0029C: CLRWDT
0029E: RETURN
....................
.................... #endif
|
Without FORCE_SW
Code: |
CCS PCD C Compiler, Version 5.073, xxxxx 19-juil.-17 15:03
Filename: C:\Users\BE1\Desktop\Programmes - Copie\main.lst
ROM used: 1374 bytes (1%)
Largest free fragment is 65536
RAM used: 116 (0%) at main() level
119 (0%) worst case
Stack used: 24 locations
Stack size: 112
*
00000: GOTO 444
.................... #include <main.h>
.................... #ifndef MAIN_H
.................... #define MAIN_H
....................
.................... #include <24EP256GU810.h>
.................... //////////// Standard Header file for the PIC24EP256GU810 device ////////////////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996, 2014 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... #device PIC24EP256GU810
*
00200: CLR 54
00202: MOV #20C,W3
00204: ADD W3,W0,W0
00206: TBLRDL.B[W0],W0L
00208: CLR.B 1
0020A: RETURN
0020C: DATA 0A,0D,00
0020E: DATA 53,74,00
00210: DATA 61,72,00
00212: DATA 74,3A,00
00214: DATA 0A,0D,00
00216: DATA 00,00,00
00218: CLR 54
0021A: MOV #224,W3
0021C: ADD W3,W0,W0
0021E: TBLRDL.B[W0],W0L
00220: CLR.B 1
00222: RETURN
00224: DATA 41,43,00
00226: DATA 4B,20,00
00228: DATA 61,64,00
0022A: DATA 64,72,00
0022C: DATA 3A,20,00
0022E: DATA 25,58,00
00230: DATA 0A,0D,00
00232: DATA 00,00,00
00234: CLR 54
00236: MOV #240,W3
00238: ADD W3,W0,W0
0023A: TBLRDL.B[W0],W0L
0023C: CLR.B 1
0023E: RETURN
00240: DATA 0A,0D,00
00242: DATA 4E,6F,00
00244: DATA 74,68,00
00246: DATA 69,6E,00
00248: DATA 67,20,00
0024A: DATA 46,6F,00
0024C: DATA 75,6E,00
0024E: DATA 64,00,00
00250: CLR 54
00252: MOV #25C,W3
00254: ADD W3,W0,W0
00256: TBLRDL.B[W0],W0L
00258: CLR.B 1
0025A: RETURN
0025C: DATA 0A,0D,00
0025E: DATA 4E,75,00
00260: DATA 6D,62,00
00262: DATA 65,72,00
00264: DATA 20,6F,00
00266: DATA 66,20,00
00268: DATA 69,32,00
0026A: DATA 63,20,00
0026C: DATA 63,68,00
0026E: DATA 69,70,00
00270: DATA 73,20,00
00272: DATA 66,6F,00
00274: DATA 75,6E,00
00276: DATA 64,3A,00
00278: DATA 20,25,00
0027A: DATA 75,00,00
*
0032A: MOV W0,W3
0032C: SWAP W1
0032E: MOV.B #5,W4L
00330: DEC.B 0003
00332: DEC.B 0008
00334: BRA Z,368
00336: MOV W3,W0
00338: SL W3,#4,W3
0033A: LSR W0,#C,W0
0033C: AND #F,W0
0033E: BRA NZ,348
00340: CP.B W4L,#1
00342: BRA Z,348
00344: BTSS.B 3.7
00346: BRA 330
00348: ADD #30,W0
0034A: MOV #3A,W2
0034C: CP W0,W2
0034E: BRA NC,352
00350: ADD.B 2,W0L
00352: MOV W1,[W15++]
00354: MOV W3,[W15++]
00356: MOV W4,[W15++]
00358: MOV.B W0L,1060
0035A: CALL 27C
0035E: MOV [--W15],W4
00360: MOV [--W15],W3
00362: MOV [--W15],W1
00364: BSET.B 3.7
00366: BRA 330
00368: RETURN
0036A: MOV W5,[W15++]
0036C: MOV #C,W5
0036E: REPEAT #3
00370: MOV [W5++],[W15++]
00372: MOV W0,W7
00374: MOV W4,W9
00376: BCLR W4.F
00378: CP0 W4
0037A: BRA NZ,388
0037C: BTSC W9.F
0037E: BRA 384
00380: MOV #0,W5
00382: BRA 3B2
00384: MOV #0,W5
00386: BRA 3B2
00388: SUB.B W4L,#6,W5L
0038A: BRA NC,3B0
0038C: MOV #30,W0
0038E: BTSS W9.F
00390: MOV #20,W0
00392: MOV W0,[W15++]
00394: MOV W1,[W15++]
00396: MOV.D W2,[W15++]
00398: MOV W4,[W15++]
0039A: MOV.B W0L,1060
0039C: CALL 27C
003A0: MOV [--W15],W4
003A2: MOV.D [--W15],W2
003A4: MOV [--W15],W1
003A6: MOV [--W15],W0
003A8: DEC W5,W5
003AA: BRA NN,392
003AC: MOV #5,W5
003AE: BRA 3B2
003B0: MOV W4,W5
003B2: MOV #6,W4
003B4: BSET W5.E
003B6: BTSC W9.F
003B8: BSET W5.F
003BA: MOV #2710,W8
003BC: REPEAT #11
003BE: DIV.U W7,W8
003C0: CALL 400
003C4: MOV W1,W7
003C6: MOV #3E8,W8
003C8: REPEAT #11
003CA: DIV.U W7,W8
003CC: CALL 400
003D0: MOV W1,W7
003D2: MOV #64,W8
003D4: REPEAT #11
003D6: DIV.U W7,W8
003D8: CALL 400
003DC: MOV W1,W7
003DE: MOV #A,W8
003E0: REPEAT #11
003E2: DIV.U W7,W8
003E4: CALL 400
003E8: MOV #30,W0
003EA: ADD.B W1L,W0L,W0L
003EC: MOV W1,[W15++]
003EE: MOV.D W2,[W15++]
003F0: MOV W4,[W15++]
003F2: MOV.B W0L,1060
003F4: CALL 27C
003F8: MOV [--W15],W4
003FA: MOV.D [--W15],W2
003FC: MOV [--W15],W1
003FE: BRA 43A
00400: MOV #30,W6
00402: CP0 W0
00404: BRA NZ,422
00406: BTSS W5.E
00408: BRA 424
0040A: DEC W4,W4
0040C: CP.B W4L,W5L
0040E: BRA Z,414
00410: BTSC.B 42.0
00412: RETURN
00414: CP0 W0
00416: BRA NZ,422
00418: BTSS W5.E
0041A: BRA 424
0041C: BTSS W5.F
0041E: MOV #20,W6
00420: BRA 424
00422: BCLR W5.E
00424: ADD.B W6L,W0L,W0L
00426: MOV W1,[W15++]
00428: MOV W2,[W15++]
0042A: MOV W4,[W15++]
0042C: MOV.B W0L,1060
0042E: CALL 27C
00432: MOV [--W15],W4
00434: MOV [--W15],W2
00436: MOV [--W15],W1
00438: RETURN
0043A: MOV #12,W5
0043C: REPEAT #3
0043E: MOV [--W15],[W5--]
00440: MOV [--W15],W5
00442: RETURN
....................
.................... #list
....................
.................... #device ADC=12
.................... #device ICSP=3
.................... #use delay(internal=47905000,restart_wdt)
*
002A0: CP0 W0
002A2: BTSC.B 42.1
002A4: BRA 2B2
002A6: REPEAT #1D8B
002A8: CLRWDT
002AA: REPEAT #3FFE
002AC: CLRWDT
002AE: DEC W0,W0
002B0: BRA NZ,2A6
002B2: RETURN
....................
.................... #FUSES WDT //Watch Dog Timer
.................... #FUSES WPRES32 //Watch Dog Timer PreScalar 1:32
.................... #FUSES WPOSTS11 //Watch Dog Timer PostScalar 1:1024
.................... #FUSES OSCIO //OSC2 is general purpose output
.................... #FUSES NOWRT //Program memory not write protected
.................... #FUSES NOPROTECT //Code not protected from reading
.................... #FUSES GSSK //General Segment Key bits, use if using either WRT or PROTECT fuses
.................... #FUSES IESO //Internal External Switch Over mode enabled
.................... #FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
.................... #FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
.................... #FUSES PLLWAIT //Clock switch to PLL will wait until the PLL lock signal is valid
.................... #FUSES WINDIS //Watch Dog Timer in non-Window mode
.................... #FUSES PUT32 //Power On Reset Timer value 32ms
.................... #FUSES BROWNOUT //Reset when brownout detected
.................... #FUSES NOALTI2C1 //I2C1 mapped to SDA1/SCL1 pins
.................... #FUSES NOALTI2C2 //I2C2 mapped to SDA2/SCL2 pins
.................... #FUSES RESET_PRIMARY //Device will reset to Primary Flash Reset location
.................... #FUSES JTAG //JTAG
.................... #FUSES NOAWRT //Auxiliary program memory is not write-protected
.................... #FUSES NOAPROTECT //Auxiliary program memory is not code-protected
.................... #FUSES APLK //Auxiliary Segment Key bits, use if using either AWRT or APROTECT fuses
....................
.................... #use i2c(MASTER, I2C2, FAST, RESTART_WDT, stream=BUS_I2C)
*
002D2: MOV #FFFF,W0
002D4: BTSS.B 218.3
002D6: BRA 2E2
002D8: BTSC.B 219.6
002DA: BRA 2D8
002DC: MOV W1,212
002DE: BTSC.B 219.6
002E0: BRA 2DE
002E2: MOV #0,W0
002E4: BTSC.B 219.7
002E6: INC W0,W0
002E8: RETURN
.................... #use rs232(xmit=PIN_C1, rcv=PIN_C2, baud=9600, errors)
*
0027C: BCLR.B E20.1
0027E: BCLR.B E24.1
00280: MOV #8,W3
00282: REPEAT #9BB
00284: CLRWDT
00286: RRC.B 1060
00288: BTSC.B 42.0
0028A: BSET.B E24.1
0028C: BTSS.B 42.0
0028E: BCLR.B E24.1
00290: REPEAT #9B6
00292: CLRWDT
00294: DEC W3,W3
00296: BRA NZ,286
00298: BSET.B E24.1
0029A: REPEAT #9BD
0029C: CLRWDT
0029E: RETURN
....................
.................... #endif
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Wed Jul 19, 2017 7:35 am |
|
|
Please get rid of the WDT, recompile and test. It's NOT required and may 'complicate' things...
As the listing shows the compiler does create SW I2C code and when using the HW the code looks OK.. (address 0x218 is an I2C #2 register).
Others who use that PIC may be able to help but the fact some code DOES work comfirms HW is OK so it may be a syntax or code style problem.
Jay |
|
|
BeeElectronic
Joined: 19 Jul 2017 Posts: 27
|
|
Posted: Wed Jul 19, 2017 7:46 am |
|
|
I already try without WDT. Same problem... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Wed Jul 19, 2017 8:59 am |
|
|
Try turning off the PMP.
This has priority over the I2C interface, but not over normal pin I/O.
So:
setup_pmp(PAR_DISABLE,0);
Depending on how your compiler version is configuring things, this could stop the I2C from running. |
|
|
BeeElectronic
Joined: 19 Jul 2017 Posts: 27
|
|
Posted: Wed Jul 19, 2017 9:47 am |
|
|
It's not better. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Wed Jul 19, 2017 3:26 pm |
|
|
You should post your small test program maybe someone can see what's happening....
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Thu Jul 20, 2017 12:58 am |
|
|
You need to talk to CCS.
I just compiled the original program, and the fault is obvious.
For some reason, it thinks I2C2CON is at the wrong address.
So a fault in the device database for the second I2C.
Interestingly it is at the right location in the register map
from the device editor, but for some reason the code it talking
to the wrong location....
They should fix this in a matter of hours only. |
|
|
BeeElectronic
Joined: 19 Jul 2017 Posts: 27
|
|
Posted: Thu Jul 20, 2017 2:18 am |
|
|
OK, I do that. |
|
|
BeeElectronic
Joined: 19 Jul 2017 Posts: 27
|
|
Posted: Fri Jul 21, 2017 2:36 am |
|
|
Quote: |
It's a known issue with v5.073 of the compiler. It has been fixed which will be available in the next compiler release we do.
Richard
CCS Support
|
So I wait for the new release |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Mon Jul 24, 2017 8:52 am |
|
|
I informed CCS of this problem a few weeks ago.
The latest update, 5.074 says they have fixed it. I have not tried it yet - usually CCS updates break something else and I'm at a tight part of the project, so sticking with 5.070 for a few more weeks.
If 5.074 fixes your problem, please let us know |
|
|
|
|
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
|