• AVR Freaks

Hot!i2c error - does not build

Author
Poley
Starting Member
  • Total Posts : 54
  • Reward points : 0
  • Joined: 2020/06/16 08:39:05
  • Location: 0
  • Status: offline
2020/10/20 09:30:20 (permalink)
0

i2c error - does not build

Hi,
 
I am trying to use the i2c block in my model however when I try to build I get the following error:
 
MCHP_I2C1_Interrupt_data.o
MCHP_I2C1_Interrupt.c: In function '_MI2C1Interrupt':
MCHP_I2C1_Interrupt.c:66:45: error: 'I2C1STATLbits' undeclared (first use in this function) MCHP_I2C1_Interrupt.c:66:45: note: each undeclared identifier is reported only once for each function it appears in
 
Has anyone seen this?
 
Thank you
 
#1
KTrenholm
Super Member
  • Total Posts : 804
  • Reward points : 0
  • Joined: 2012/08/08 14:04:23
  • Location: Connecticut, USA
  • Status: offline
Re: i2c error - does not build 2020/10/20 09:47:05 (permalink)
0
Well you're referencing a structure for the I2C1STATL register that appears to not exist for one reason or another.
 
What PIC specifically are you using?  Can you confirm if it has a I2C1STATL register from the datasheet?
If it does have a I2C1STATL register, are you including xc.h for these register struct definitions?
 
Need more info (like what PIC you are using and what compiler/toolchain you are using) to help any further.
post edited by KTrenholm - 2020/10/20 09:49:24
#2
Poley
Starting Member
  • Total Posts : 54
  • Reward points : 0
  • Joined: 2020/06/16 08:39:05
  • Location: 0
  • Status: offline
Re: i2c error - does not build 2020/10/20 09:49:36 (permalink)
0
I am using dsPIC33EV256GM106.
 
It does not appear to have I2C1STATL but it does have I2C1STAT
 
Thanks
#3
KTrenholm
Super Member
  • Total Posts : 804
  • Reward points : 0
  • Joined: 2012/08/08 14:04:23
  • Location: Connecticut, USA
  • Status: offline
Re: i2c error - does not build 2020/10/20 09:55:24 (permalink)
0
Is it possible that the code you have was written for a different PIC?  It sounds like whatever it was written for splits I2CSTAT into high and low registers.
 
You may need to convert from whatever PIC this was written for to the dsPIC you are using.
This would mean finding the equivalent bit/register on your part and adjusting your code accordingly.
 
Can you post the code from your _MI2C1Interrupt?
 
Also I just noticed this is the MATLAB board.  I'm not very knowledgeable on MATLAB (and I've never used it with a PIC), so not sure how much actual help I will be able to give.
post edited by KTrenholm - 2020/10/20 09:57:44
#4
Poley
Starting Member
  • Total Posts : 54
  • Reward points : 0
  • Joined: 2020/06/16 08:39:05
  • Location: 0
  • Status: offline
Re: i2c error - does not build 2020/10/20 10:01:24 (permalink)
0
Yeah sure, it is passed the matlab build so it is the code side luckily
 
/* I2C - Interrupt: <S50>/BUS I2C MASTER2 */
/* Implement I2C 1 Interrupts */
void __attribute__((__interrupt__,__shadow__,__no_auto_psv__)) _MI2C1Interrupt
  (void) /* MI2C1 ISR */
{
  boolean_T Continue;
  _MI2C1IF = 0; /* Clear I2C1 Master Interrupt */

  /* Declaration of Variables */
  do {
    Continue = 0; /* By default, execute one sequence only */
    switch (MCHP_I2C1_State)
    {
     case 0: /* Idle */
      /* Check if the next sequence is already in the queue. If so, start it */
      Continue = (MCHP_I2C1_Queue.head != MCHP_I2C1_Queue.tail);
                                    /* One next sequence queued, start it now */
      if (Continue) {
        MCHP_I2C1_State = MCHP_I2C1_Queue.buffer[MCHP_I2C1_Queue.tail];
        if (MCHP_I2C1_Queue.tail >= 3)
                           /* There are 3 I2C1 blocks, max idx for queue is 3 */
          MCHP_I2C1_Queue.tail = 0;
        else
          MCHP_I2C1_Queue.tail++;
      }
      break;

     case 1:
          /* Problem: try Reset of I2C BUS : Repeated Start sequence and Stop */
      TRISBbits.TRISB5 = 1;/* Set I2C Port as Port Input (better for Fj chips)*/
      TRISBbits.TRISB6 = 1;
      I2C1CONLbits.I2CEN = 1; /* Re-Enable I2C*/
      I2C1STAT &= 65526; /* Reset I2C State */
      I2C1CONLbits.RSEN = 1; /* I2C: Restart */
      MCHP_I2C1_State++;
      break;

     case 2: /* Problem: try Reset of I2C BUS : Stop sequence*/
      I2C1STAT &= 65526;
      /* Reset I2C Receive Overflow and I2C Collision during Write or Master operation */
      I2C1CONLbits.PEN = 1; /* I2C: STOP */
      MCHP_I2C1_State++;
      break;

     case 3:
      I2C1STAT &= 65526;
      /* Reset I2C Receive Overflow and I2C Collision during Write or Master operation */
      MCHP_I2C1_State = 0;
      Continue = (MCHP_I2C1_Queue.head != MCHP_I2C1_Queue.tail);/* Any pending sequence ? */
      break;

     case 4: /* Start a new I2C Sequence */
      I2C1CONLbits.SEN = 1; /* I2C: START */
      MCHP_I2C1_State++;
      break;

     case 5:
      I2C1TRN = 0xA0; /* Send I2C Address : A7 A6 A5 A4 A3 A2 A1 A0 RW */
      MCHP_I2C1_State++;
      break;

     case 6:
      MCHP_I2C13_SequenceCompleted -= (int) I2C1STATLbits.ACKSTAT;
                           /* decrement on NACK: sequence completed remains 0 */
      I2C1TRN = 0x1F; /* I2C : Write data */
      MCHP_I2C1_State++;
      break;

     case 7:
      MCHP_I2C13_SequenceCompleted -= (int) I2C1STATLbits.ACKSTAT;
                           /* decrement on NACK: sequence completed remains 0 */
      I2C1TRN = 0xF0; /* I2C : Write data */
      MCHP_I2C1_State++;
      break;

     case 8:
      MCHP_I2C13_SequenceCompleted -= (int) I2C1STATLbits.ACKSTAT;
                           /* decrement on NACK: sequence completed remains 0 */
      I2C1CONLbits.RSEN = 1; /* I2C: REPEATED START */
      MCHP_I2C1_State++;
      break;

     case 9:
      I2C1TRN = 0xA1; /* Send I2C Address : A7 A6 A5 A4 A3 A2 A1 A0 RW */
      MCHP_I2C1_State++;
      break;

     case 10:
      MCHP_I2C13_SequenceCompleted -= (int) I2C1STATLbits.ACKSTAT;
                           /* decrement on NACK: sequence completed remains 0 */
      I2C1CONLbits.RCEN = 1; /* I2C: Receive */
      MCHP_I2C1_State++;
      break;

     case 11:
      I2C13_Buff8[0] = I2C1RCV; /* I2C : Read data */
      I2C1CONLbits.ACKDT = 0; /* set to ACK */
      I2C1CONLbits.ACKEN = 1; /* Start Acknowledge sequence */
      MCHP_I2C1_State++;
      break;

     case 12:
      I2C1CONLbits.RCEN = 1; /* I2C: Receive */
      MCHP_I2C1_State++;
      break;

     case 13:
      I2C13_Buff8[1] = I2C1RCV; /* I2C : Read data */
      I2C1CONLbits.ACKDT = 0; /* set to ACK */
      I2C1CONLbits.ACKEN = 1; /* Start Acknowledge sequence */
      MCHP_I2C1_State++;
      break;

     case 14:
      I2C1CONLbits.RCEN = 1; /* I2C: Receive */
      MCHP_I2C1_State++;
      break;

     case 15:
      I2C13_Buff8[2] = I2C1RCV; /* I2C : Read data */
      I2C1CONLbits.ACKDT = 0; /* set to ACK */
      I2C1CONLbits.ACKEN = 1; /* Start Acknowledge sequence */
      MCHP_I2C1_State++;
      break;

     case 16:
      I2C1CONLbits.RCEN = 1; /* I2C: Receive */
      MCHP_I2C1_State++;
      break;

     case 17:
      I2C13_Buff8[3] = I2C1RCV; /* I2C : Read data */
      I2C1CONLbits.ACKDT = 1; /* set to NACK */
      I2C1CONLbits.ACKEN = 1; /* Start Acknowledge sequence */
      MCHP_I2C1_State++;
      break;

     case 18:
      I2C1CONLbits.PEN = 1; /* I2C: STOP */
      MCHP_I2C1_State++;
      break;

     case 19:
      MCHP_I2C13_SequenceCompleted += 1;
                                    /* is 1 only if no NACK were encountered. */
      MCHP_I2C13_Request = 0; /* This I2C sequence could be Re-Enabled */
      MCHP_I2C1_State = 0;
      Continue = (MCHP_I2C1_Queue.head != MCHP_I2C1_Queue.tail);
                                    /* One next sequence queued, start it now */
      break;

     case 20: /* Start a new I2C Sequence */
      I2C1CONLbits.SEN = 1; /* I2C: START */
      MCHP_I2C1_State++;
      break;

     case 21:
      I2C1TRN = 0xA0; /* Send I2C Address : A7 A6 A5 A4 A3 A2 A1 A0 RW */
      MCHP_I2C1_State++;
      break;

     case 22:
      MCHP_I2C11_SequenceCompleted -= (int) I2C1STATLbits.ACKSTAT;
                           /* decrement on NACK: sequence completed remains 0 */
      I2C1TRN = I2C11_Buff8[0]; /* I2C : Write data */
      MCHP_I2C1_State++;
      break;

     case 23:
      MCHP_I2C11_SequenceCompleted -= (int) I2C1STATLbits.ACKSTAT;
                           /* decrement on NACK: sequence completed remains 0 */
      I2C1TRN = I2C11_Buff8[1]; /* I2C : Write data */
      MCHP_I2C1_State++;
      break;

     case 24:
      MCHP_I2C11_SequenceCompleted -= (int) I2C1STATLbits.ACKSTAT;
                           /* decrement on NACK: sequence completed remains 0 */
      I2C1TRN = I2C11_Buff8[2]; /* I2C : Write data */
      MCHP_I2C1_State++;
      break;

     case 25:
      MCHP_I2C11_SequenceCompleted -= (int) I2C1STATLbits.ACKSTAT;
                           /* decrement on NACK: sequence completed remains 0 */
      I2C1TRN = I2C11_Buff8[3]; /* I2C : Write data */
      MCHP_I2C1_State++;
      break;

     case 26:
      MCHP_I2C11_SequenceCompleted -= (int) I2C1STATLbits.ACKSTAT;
                           /* decrement on NACK: sequence completed remains 0 */
      I2C1CONLbits.PEN = 1; /* I2C: STOP */
      MCHP_I2C1_State++;
      break;

     case 27:
      MCHP_I2C11_SequenceCompleted += 1;
                                    /* is 1 only if no NACK were encountered. */
      MCHP_I2C11_Request = 0; /* This I2C sequence could be Re-Enabled */
      MCHP_I2C1_State = 0;
      Continue = (MCHP_I2C1_Queue.head != MCHP_I2C1_Queue.tail);
                                    /* One next sequence queued, start it now */
      break;

     case 28: /* Start a new I2C Sequence */
      I2C1CONLbits.SEN = 1; /* I2C: START */
      MCHP_I2C1_State++;
      break;

     case 29:
      I2C1TRN = 0xA0; /* Send I2C Address : A7 A6 A5 A4 A3 A2 A1 A0 RW */
      MCHP_I2C1_State++;
      break;

     case 30:
      MCHP_I2C12_SequenceCompleted -= (int) I2C1STATLbits.ACKSTAT;
                           /* decrement on NACK: sequence completed remains 0 */
      I2C1TRN = I2C12_Buff8[0]; /* I2C : Write data */
      MCHP_I2C1_State++;
      break;

     case 31:
      MCHP_I2C12_SequenceCompleted -= (int) I2C1STATLbits.ACKSTAT;
                           /* decrement on NACK: sequence completed remains 0 */
      I2C1TRN = I2C12_Buff8[1]; /* I2C : Write data */
      MCHP_I2C1_State++;
      break;

     case 32:
      MCHP_I2C12_SequenceCompleted -= (int) I2C1STATLbits.ACKSTAT;
                           /* decrement on NACK: sequence completed remains 0 */
      I2C1TRN = I2C12_Buff8[2]; /* I2C : Write data */
      MCHP_I2C1_State++;
      break;

     case 33:
      MCHP_I2C12_SequenceCompleted -= (int) I2C1STATLbits.ACKSTAT;
                           /* decrement on NACK: sequence completed remains 0 */
      I2C1TRN = I2C12_Buff8[3]; /* I2C : Write data */
      MCHP_I2C1_State++;
      break;

     case 34:
      MCHP_I2C12_SequenceCompleted -= (int) I2C1STATLbits.ACKSTAT;
                           /* decrement on NACK: sequence completed remains 0 */
      I2C1CONLbits.PEN = 1; /* I2C: STOP */
      MCHP_I2C1_State++;
      break;

     case 35:
      MCHP_I2C12_SequenceCompleted += 1;
                                    /* is 1 only if no NACK were encountered. */
      MCHP_I2C12_Request = 0; /* This I2C sequence could be Re-Enabled */
      MCHP_I2C1_State = 0;
      Continue = (MCHP_I2C1_Queue.head != MCHP_I2C1_Queue.tail);
                                    /* One next sequence queued, start it now */
      break;

     default: /* Sequence finished */
      MCHP_I2C1_State = 0; /* Should never happend */
      break;
    } /* End of switch case sequence*/
  } while (Continue == 1); /* end do-While */
} /* Enf of interrupt */

 
Thanks 
 
#5
KTrenholm
Super Member
  • Total Posts : 804
  • Reward points : 0
  • Joined: 2012/08/08 14:04:23
  • Location: Connecticut, USA
  • Status: offline
Re: i2c error - does not build 2020/10/20 10:07:37 (permalink)
0
OK it looks like a number of them correspond to I2C1CON1.
 
Try:
I2C1CONLbits.I2CEN -> I2C1CON1bits.I2CEN
I2C1CONLbits.RSEN -> I2C1CON1bits.RSEN
etc.
#6
Poley
Starting Member
  • Total Posts : 54
  • Reward points : 0
  • Joined: 2020/06/16 08:39:05
  • Location: 0
  • Status: offline
Re: i2c error - does not build 2020/10/20 10:18:16 (permalink)
0
I haven't got a clue how to edit the simulink block that produces this .c file to make that change (It is auto generated).
 
Looks like it's when I request a acknowledgement that makes it throw the error. I don't have these bits 
I2C1CONLbits.ACKDT = 0; /* set to ACK */
I2C1CONLbits.ACKEN = 1; /* Start Acknowledge sequence */ 
 
for any I2C1CON#
#7
KTrenholm
Super Member
  • Total Posts : 804
  • Reward points : 0
  • Joined: 2012/08/08 14:04:23
  • Location: Connecticut, USA
  • Status: offline
Re: i2c error - does not build 2020/10/20 11:05:39 (permalink)
0
ACKDT and ACKEN should be bits 5 and 4 of I2C1CON1 according to the datasheet
http://ww1.microchip.com/...eviceDoc/70005144e.pdf
I2C Registers begin at page 231.
 
Afraid I can't help much with how to change how simulink generates its code unfortunately.
#8
Poley
Starting Member
  • Total Posts : 54
  • Reward points : 0
  • Joined: 2020/06/16 08:39:05
  • Location: 0
  • Status: offline
Re: i2c error - does not build 2020/10/20 11:46:09 (permalink)
0
Ah yeah you're right, it does indeed have those included, it must be the wat that file is generated then. 
 
Hopefully Lubin sees this and could offer some insight on how to change I2C1CONL into I2C1CON1
 
Thanks for the help
#9
Poley
Starting Member
  • Total Posts : 54
  • Reward points : 0
  • Joined: 2020/06/16 08:39:05
  • Location: 0
  • Status: offline
Re: i2c error - does not build 2020/10/20 11:48:03 (permalink)
0
Actually it does have this in the datasheet, even weirder that it's not working.
 
So it is definitely I2C1STATL that is causing the issue (Should be I2C1STAT from the datasheet)
 
#define I2C1CONL I2C1CONL
extern volatile uint16_t I2C1CONL __attribute__((__sfr__));
typedef struct tagI2C1CONLBITS {
  uint16_t SEN:1;
  uint16_t RSEN:1;
  uint16_t PEN:1;
  uint16_t RCEN:1;
  uint16_t ACKEN:1;
  uint16_t ACKDT:1;
  uint16_t STREN:1;
  uint16_t GCEN:1;
  uint16_t SMEN:1;
  uint16_t DISSLW:1;
  uint16_t A10M:1;
  uint16_t STRICT:1;
  uint16_t SCLREL:1;
  uint16_t I2CSIDL:1;
  uint16_t :1;
  uint16_t I2CEN:1;
} I2C1CONLBITS;
extern volatile I2C1CONLBITS I2C1CONLbits __attribute__((__sfr__));

post edited by Poley - 2020/10/20 11:50:31
#10
Poley
Starting Member
  • Total Posts : 54
  • Reward points : 0
  • Joined: 2020/06/16 08:39:05
  • Location: 0
  • Status: offline
Re: i2c error - does not build 2020/10/20 12:07:03 (permalink)
0
Update: Went through and changed the .tlc file to be STAT rather than STATL
 
Error says this now:
 
gmake: *** [BMS_Danecca_2020_main.o] Error 255
gmake: *** Waiting for unfinished jobs....
gmake: *** [MCHP_I2C1_Interrupt_data.o] Error 255
gmake: *** [MCHP_I2C1_Interrupt.o] Error 255
 
Hopefully Lubin cant help out, thanks 
#11
Lubin
Moderator
  • Total Posts : 447
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: i2c error - does not build 2020/10/21 08:35:59 (permalink)
0
Hi Poley,
 
Thanks for the report. Could you test a version with a fix here:
https://github.com/LubinKerhuel/MPLAB-Device-Blocks-for-Simulink/archive/Beta.zip
 
Thanks,
Lubin
#12
Poley
Starting Member
  • Total Posts : 54
  • Reward points : 0
  • Joined: 2020/06/16 08:39:05
  • Location: 0
  • Status: offline
Re: i2c error - does not build 2020/10/22 01:01:17 (permalink)
0
Hi Lubin,
 
I got it working by removing I2CRefReg after all instances of I2C1STAT in the MCHP_I2C_BUS_MASTER .tlc file.
 
Is your fix similar to this? Do I need to uninstall my current blockset to load this one in?
 
Thanks
#13
Lubin
Moderator
  • Total Posts : 447
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: i2c error - does not build 2020/10/22 03:07:22 (permalink)
0
Hi Poley,
 
The fix deals with the TLC variable "I2CRefRegEnd" which should not be used in the I2CxSTAT register.
 
Please save your modified TLC file in case and give a try to the updated version.
 
#14
Poley
Starting Member
  • Total Posts : 54
  • Reward points : 0
  • Joined: 2020/06/16 08:39:05
  • Location: 0
  • Status: offline
Re: i2c error - does not build 2020/10/22 11:29:59 (permalink)
0
Yep that seems to work, thanks.
 
My model seems to crash after running for about 10 seconds on my hardware, do you know what kind of things could cause this behaviour? Thanks!
#15
Lubin
Moderator
  • Total Posts : 447
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: i2c error - does not build 2020/10/22 12:06:47 (permalink)
0
Hi Poley,
 
Thanks for your feedback.
 
Please try creating a new thread for each new topic
Provide as much details on the problem to help resolution.
Regarding the crash, does the MCU reset or stop ? did you measured CPU load ? Is the model compiled with a single tasking or multi tasking implementation ?  Did you add something which makes it crash or does the system always reset after 10s whatever the content of the model ? 
 
 
 
#16
Poley
Starting Member
  • Total Posts : 54
  • Reward points : 0
  • Joined: 2020/06/16 08:39:05
  • Location: 0
  • Status: offline
Re: i2c error - does not build 2020/10/22 12:12:11 (permalink)
3 (1)
The MCU stops rather than resets. 
 
I think I have narrowed it down to my CAN send function that makes it stop, I changed it from 1 message to 16. I am using multi-tasking.
 
How would I see CPU load? put it onto the CAN bus and read what it was when it crashed?
 
Thanks!
#17
Lubin
Moderator
  • Total Posts : 447
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: i2c error - does not build 2020/10/22 12:31:03 (permalink)
0
You could either use pin toggling to get visualisaiton of what's happening for each tasks or for the overall load.
You can also get a measured value.
Please visit that thread: https://www.microchip.com/forums/FindPost/1120678
 
 
 
#18
Poley
Starting Member
  • Total Posts : 54
  • Reward points : 0
  • Joined: 2020/06/16 08:39:05
  • Location: 0
  • Status: offline
Re: i2c error - does not build 2020/10/22 23:46:59 (permalink)
0
Ok so playing with tbf any other things I narrowed it down to an error in my CAN code, I was switching it off before it had chance to clear the buffer.

The other issue that’s making it hang is a stateflow chart which does not run on hardware. Not sure if I have too much running at the same rate? Could that cause the issue?
#19
Jump to:
© 2020 APG vNext Commercial Version 4.5