Pinguino Forum

Full Version: Wire compile error, I2C wrong results
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to talk to an i2c-device with 45k50/v12, but having trouble.

Firstly, I cannot use any of the Wire module examples. Compile errors are along these lines:




Code:
2018-09-23 22:08:13.273051
######################################################################
/dvpt/pinguino/git-copy/pinguino-compilers/sources/sdcc/src/pic16/main.c:701 setting interrupt vector addresses 0xc00
Processor: 18f45k50
sdcc: Calling linker...
+ /opt/pinguino/p8/bin/gplink -I/opt/pinguino/p8/bin/../share/sdcc/lib/pic16 -I/dvpt/pinguino/git-copy/pinguino-compilers/linux64/p8/share/sdcc/lib/pic16 -I/opt/pinguino/p8/bin/../share/sdcc/non-free/lib/pic16 -I/dvpt/pinguino/git-copy/pinguino-compilers/linux64/p8/share/sdcc/non-free/lib/pic16  -s"/opt/pinguino/v12/p8/lkr/boot4.18f45k50.lkr" -m  -w -r -o /home/lash/Pinguino/v12/source/main.hex  /home/lash/Pinguino/v12/source/main.o   libio18f45k50.lib libdev18f45k50.lib libc18f.lib libm18f.lib libdev18f45k50.lib libsdcc.lib 






2018-09-23 22:09:34.728329
######################################################################
/dvpt/pinguino/git-copy/pinguino-compilers/sources/sdcc/src/pic16/main.c:701 setting interrupt vector addresses 0xc00
Processor: 18f45k50
sdcc: Calling linker...
+ /opt/pinguino/p8/bin/gplink -I/opt/pinguino/p8/bin/../share/sdcc/lib/pic16 -I/dvpt/pinguino/git-copy/pinguino-compilers/linux64/p8/share/sdcc/lib/pic16 -I/opt/pinguino/p8/bin/../share/sdcc/non-free/lib/pic16 -I/dvpt/pinguino/git-copy/pinguino-compilers/linux64/p8/share/sdcc/non-free/lib/pic16  -s"/opt/pinguino/v12/p8/lkr/boot4.18f45k50.lkr" -m  -w -r -o /home/lash/Pinguino/v12/source/main.hex  /home/lash/Pinguino/v12/source/main.o   libio18f45k50.lib libdev18f45k50.lib libc18f.lib libm18f.lib libdev18f45k50.lib libsdcc.lib 






2018-09-23 22:10:40.771238
######################################################################
/dvpt/pinguino/git-copy/pinguino-compilers/sources/sdcc/src/pic16/main.c:701 setting interrupt vector addresses 0xc00
Processor: 18f45k50
sdcc: Calling linker...
+ /opt/pinguino/p8/bin/gplink -I/opt/pinguino/p8/bin/../share/sdcc/lib/pic16 -I/dvpt/pinguino/git-copy/pinguino-compilers/linux64/p8/share/sdcc/lib/pic16 -I/opt/pinguino/p8/bin/../share/sdcc/non-free/lib/pic16 -I/dvpt/pinguino/git-copy/pinguino-compilers/linux64/p8/share/sdcc/non-free/lib/pic16  -s"/opt/pinguino/v12/p8/lkr/boot4.18f45k50.lkr" -m  -w -r -o /home/lash/Pinguino/v12/source/main.hex  /home/lash/Pinguino/v12/source/main.o   libio18f45k50.lib libdev18f45k50.lib libc18f.lib libm18f.lib libdev18f45k50.lib libsdcc.lib 






2018-09-23 22:11:37.483560
######################################################################
/dvpt/pinguino/git-copy/pinguino-compilers/sources/sdcc/src/pic16/main.c:701 setting interrupt vector addresses 0xc00
Processor: 18f45k50
sdcc: Calling linker...
+ /opt/pinguino/p8/bin/gplink -I/opt/pinguino/p8/bin/../share/sdcc/lib/pic16 -I/dvpt/pinguino/git-copy/pinguino-compilers/linux64/p8/share/sdcc/lib/pic16 -I/opt/pinguino/p8/bin/../share/sdcc/non-free/lib/pic16 -I/dvpt/pinguino/git-copy/pinguino-compilers/linux64/p8/share/sdcc/non-free/lib/pic16  -s"/opt/pinguino/v12/p8/lkr/boot4.18f45k50.lkr" -m  -w -r -o /home/lash/Pinguino/v12/source/main.hex  /home/lash/Pinguino/v12/source/main.o   libio18f45k50.lib libdev18f45k50.lib libc18f.lib libm18f.lib libdev18f45k50.lib libsdcc.lib 






2018-09-23 22:12:03.135312
######################################################################
/dvpt/pinguino/git-copy/pinguino-compilers/sources/sdcc/src/pic16/main.c:701 setting interrupt vector addresses 0xc00
Processor: 18f45k50
sdcc: Calling linker...
+ /opt/pinguino/p8/bin/gplink -I/opt/pinguino/p8/bin/../share/sdcc/lib/pic16 -I/dvpt/pinguino/git-copy/pinguino-compilers/linux64/p8/share/sdcc/lib/pic16 -I/opt/pinguino/p8/bin/../share/sdcc/non-free/lib/pic16 -I/dvpt/pinguino/git-copy/pinguino-compilers/linux64/p8/share/sdcc/non-free/lib/pic16  -s"/opt/pinguino/v12/p8/lkr/boot4.18f45k50.lkr" -m  -w -r -o /home/lash/Pinguino/v12/source/main.hex  /home/lash/Pinguino/v12/source/main.o   libio18f45k50.lib libdev18f45k50.lib libc18f.lib libm18f.lib libdev18f45k50.lib libsdcc.lib 






2018-09-23 22:14:55.371715
######################################################################
/dvpt/pinguino/git-copy/pinguino-compilers/sources/sdcc/src/pic16/main.c:701 setting interrupt vector addresses 0xc00
In file included from /opt/pinguino/v12/p8/include/pinguino/core/serial.c:56,
                 from /home/lash/Pinguino/v12/source/define.h:7,
                 from /home/lash/Pinguino/v12/source/main.c:44:
/opt/pinguino/v12/p8/include/pinguino/libraries/printFormated.c:344:5: warning: "/*" within comment
/opt/pinguino/v12/p8/include/pinguino/libraries/printFormated.c:387:5: warning: "/*" within comment
/opt/pinguino/v12/p8/include/pinguino/libraries/printFormated.c:416:9: warning: "/*" within comment
/opt/pinguino/v12/p8/include/pinguino/libraries/printFormated.c:459:13: warning: "/*" within comment
In file included from /home/lash/Pinguino/v12/source/main.c:61:
/home/lash/Pinguino/v12/source/user.c:25:27: error: macro "I2C1_begin" requires 3 arguments, but only 2 given
/opt/pinguino/v12/p8/include/pinguino/core/i2cslave.c:161: warning 85: in function i2c_hw_slave_on_state_1 unreferenced function argument : '_trash'
/opt/pinguino/v12/p8/include/pinguino/core/i2cmaster.c:178: error 102: too few parameters
/opt/pinguino/v12/p8/include/pinguino/core/i2cmaster.c:184: error 102: too few parameters
/opt/pinguino/v12/p8/include/pinguino/core/i2cmaster.c:193: error 102: too few parameters
/opt/pinguino/v12/p8/include/pinguino/core/i2cmaster.c:277: error 102: too few parameters
/opt/pinguino/v12/p8/include/pinguino/core/i2cmaster.c:283: error 102: too few parameters
/opt/pinguino/v12/p8/include/pinguino/core/i2cmaster.c:292: error 102: too few parameters
-:0: warning 85: in function I2C_writeTo unreferenced function argument : 'wait'
/opt/pinguino/v12/p8/include/pinguino/core/i2cmaster.c:345: warning 85: in function I2C_transmit unreferenced function argument : 'module'
/opt/pinguino/v12/p8/include/pinguino/core/i2cmaster.c:413: warning 85: in function I2C_beginTransmission unreferenced function argument : 'module'
/opt/pinguino/v12/p8/include/pinguino/core/i2cmaster.c:530: warning 85: in function I2C_available unreferenced function argument : 'module'
/opt/pinguino/v12/p8/include/pinguino/core/i2cmaster.c:561: warning 85: in function I2C_outBuffer unreferenced function argument : 'module'
/opt/pinguino/v12/p8/include/pinguino/core/i2cmaster.c:574: warning 85: in function peek unreferenced function argument : 'module'
/opt/pinguino/v12/p8/include/pinguino/core/i2cmaster.c:596: error 102: too few parameters
/opt/pinguino/v12/p8/include/pinguino/libraries/printFormated.c:198: warning 85: in function pprinti unreferenced function argument : 'separator'
/opt/pinguino/v12/p8/include/pinguino/libraries/printFormated.c:500: warning 85: in function pprintfl unreferenced local variable : 'i'
/opt/pinguino/v12/p8/include/pinguino/libraries/printFormated.c:500: warning 85: in function pprintfl unreferenced local variable : 'rounding'
/opt/pinguino/v12/p8/include/pinguino/libraries/printFormated.c:500: warning 85: in function pprintfl unreferenced function argument : 'separator'
-:0: warning 85: in function Serial_begin unreferenced local variable : 'UART_HalfBitDelay'
-:0: warning 85: in function Serial_begin unreferenced function argument : 'args'
/home/lash/Pinguino/v12/source/user.c:25: error 20: Undefined identifier 'I2C1_begin'
/home/lash/Pinguino/v12/source/user.c:26: warning 154: converting integral to pointer without a cast
from type 'const-unsigned-char literal'
  to type 'void function ( unsigned-char fixed) code* fixed'
/home/lash/Pinguino/v12/source/user.c:26: error 101: too many parameters 
/home/lash/Pinguino/v12/source/user.c:42: error 102: too few parameters
/home/lash/Pinguino/v12/source/user.c:44: error 20: Undefined identifier 'Wire'
/home/lash/Pinguino/v12/source/user.c:44: error 25: Structure/Union expected left of '.->'
/home/lash/Pinguino/v12/source/user.c:44: error 47: indirections to different types assignment   
from type 'void'
  to type 'unsigned-char fixed'
-:0: warning 85: in function receiveEvent unreferenced local variable : 'x'
-:0: warning 85: in function receiveEvent unreferenced function argument : 'count'
Processor: 18f45k50
sdcc: Calling preprocessor...
sdcc: sdcpp -nostdinc -Wall -DPINGUINO45K50 -Dboot4 -DBOARD=\"PINGUINO45K50\" -DPROC=\"18f45k50\" -DBOOT_VER=4 -I/opt/pinguino/v12/p8/include/pinguino/core -I/opt/pinguino/v12/p8/include/pinguino/libraries -I/home/lash/tmp -D__18f45k50 -D__SDCC_PIC18F45K50 -D__STACK_MODEL_SMALL -obj-ext=.o -D__SDCC_USE_NON_FREE -D__SDCC_ALL_CALLEE_SAVES -D__SDCC=3_5_5 -D__SDCC_VERSION_MAJOR=3 -D__SDCC_VERSION_MINOR=5 -D__SDCC_VERSION_PATCH=5 -DSDCC=355 -D__SDCC_REVISION=9410 -D__SDCC_pic16 -D__STDC_NO_COMPLEX__ -D__STDC_NO_THREADS__ -D__STDC_NO_ATOMICS__ -D__STDC_NO_VLA__ -isystem /opt/pinguino/p8/bin/../share/sdcc/include/pic16 -isystem /dvpt/pinguino/git-copy/pinguino-compilers/linux64/p8/share/sdcc/include/pic16 -isystem /opt/pinguino/p8/bin/../share/sdcc/include -isystem /dvpt/pinguino/git-copy/pinguino-compilers/linux64/p8/share/sdcc/include -isystem /opt/pinguino/p8/bin/../share/sdcc/non-free/include/pic16 -isystem /dvpt/pinguino/git-copy/pinguino-compilers/linux64/p8/share/sdcc/non-free/include/pic16 -isystem /opt/pinguino/p8/bin/../share/sdcc/non-free/include -isystem /dvpt/pinguino/git-copy/pinguino-compilers/linux64/p8/share/sdcc/non-free/include  /home/lash/Pinguino/v12/source/main.c 
sdcc: Generating code...


When I use the I2C module, it compiles, but when running the results are unpredictable.

In this code I'm trying to communicate with an EEPROM chip http://ww1.microchip.com/downloads/en/devicedoc/doc0336.pdf ... sometimes I read nothing, sometimes I read 0, sometimes I read the device address I've written (a2, a3).


Code:
u8 remote = 0xA2;
u8 local = 0xA4;
u8 state = 0;
u8 writes[3] = {0, 0, 0};
u8 res[3] = {0, 0, 0};

void setState(u8 s) {
   state = s;
   if (state == 255) {
       digitalWrite(USERLED, HIGH);
   }
}

void setup() {
   // put your setup code here, to run once:
   I2C.slave(local);
   delay(1000);
}

void loop() {  
   u8 i;
   if (state == 0) {
       I2C.start();

// start read
       if (!I2C.write(remote & 0)) {
           setState(255);
           return;
       }

// memory pos 0x-101
       if (!I2C.write(0x01)) {
           setState(255);
           return;
       }
       if (!I2C.write(0x01)) {
           setState(255);
           return;
       }

// write 0x66 to memory address
       if (!I2C.write(0x66)) {
           setState(255);
           return;
       }
       I2C.stop();
       setState(1);

// status led to indicate remote write busy
       digitalWrite(5, HIGH);
       return;
   } else if (state == 1) {

// noack until busy
       I2C.start();

// write again
       if (!I2C.write(remote & 0)) {
// keep track of attempts
           writes[1]++;
           I2C.stop();
           return;
       }
// turn off busyled
       digitalWrite(5, LOW);

// read address 0x-101
       if (!I2C.write(0x01)) {
           setState(255);
           return;
       }
       if (!I2C.write(0x01)) {
           setState(255);
           return;
       }
// new start and write read request
       I2C.restart();
       if (!I2C.write(remote & 1)) {
           setState(255);
           return;
       }
// read one byte and send stop
       res[0] = I2C.read();
       I2C.stop();
       digitalWrite(6, HIGH);
       setState(2);
       
   } else {
// wot got?
       CDC.printf("res: %x.%x.%x ... %d\r\n", res[0], res[1], res[2], writes[1]);
       delay(1000);    
   }
   return;
}


I see in the I2C library docs the following is written:


Quote:The current implementation of the 8bits / I2C library (April 2014) allows
- single master operations with peripheral slave devices as PCF8574, PCF8593, DS1307, etc...(not MCU)
- single master operations with a slave MCU



Since the remote unit is the master (to my knowledge that means the one who is clocking), does that mean the library doesn't support what I'm trying to do? Or am I just not understanding how to use this properly?

Thanks.
Concerning the latter part of this, I had it all wrong;

* the MCU should be the master
* I was missing pull-up resistors

These things amended, it works fine.

The problem with the `Wire` library is still an issue, though.