• AVR Freaks

Hot!I2C2_MasterWrite() function in i2c2.c always generates a TRAPS_halt_on_error

Author
jmueckl@martinuav.com
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2016/07/14 13:25:50
  • Location: 0
  • Status: offline
2016/08/01 14:23:07 (permalink)
0

I2C2_MasterWrite() function in i2c2.c always generates a TRAPS_halt_on_error

I am using code generated by MCC for the dsPIC33EP64GP502 processor on my prototype board.  The problem is that the I2C2_MasterWrite() function always generates a TRAPS_halt_on_error with the value of 2 in the following function:
void __attribute__((naked, noreturn, weak)) TRAPS_halt_on_error(uint16_t code)
{
    TRAPS_error_code = code;
...
 
MCC generated the files mcc.c and i2c2.c, among others, which inspired me to use the I2C2_MasterWrite() function.    
Can anyone help me understand the cause of this trap?  I couldn't find any information using Google to understand the error TRAPS_halt_on_error. 
 
I verified the signal integrity of the I2C clock and SDA signals using oscilloscope using a bit banged implementation using standard _LATB14 and _LATB15 functions and saw the SDA and SCL signals wiggle as programmed.  However, using the MCC generated functions, these same signals did not even wiggle. 
 
I verified that the slave device I am talking to (PCA9685) is enabled using an oscilloscope on the enable signal.
 
The pertinent code generating the error is as follows
 
int main(void)
{
    // initialize the device
    SYSTEM_Initialize();
    /* Specify as outputs */
    _TRISB1  = 0;   // RB1
    _TRISB4  = 0;   // RB4
    _TRISB13 = 0;   // ~OE for PCA9685
    _TRISB14 = 0;   // RB14 
    _TRISB15 = 0;   // RB15
      pca9685_init();
      .....
 
The code produced by MCC for SYSTEM_Initialize is:
 
void SYSTEM_Initialize(void)
{
    PIN_MANAGER_Initialize();
    INTERRUPT_Initialize();
    OSCILLATOR_Initialize();
    UART2_Initialize();
    SPI1_Initialize();
    UART1_Initialize();
    I2C2_Initialize();
    EXT_INT_Initialize();
    TMR1_Initialize();
    INTERRUPT_GlobalEnable();
    CORCON_ModeOperatingSet(CORCON_MODE_PORVALUES);
}
 
int pca9685_init()
{
    uint8_t WriteData[3];
      I2C2_MESSAGE_STATUS status = I2C2_MESSAGE_PENDING;
      uint16_t slaveDeviceAddress = SLAVE_DEV_ADDRESS;
           
     WriteData[0] = (MODE1 >> 8);         // PCA9685 Subaddress
     WriteData[1] = (uint8_t)(MODE1);
     WriteData[2] = 0b00110001;     // Setting mode to sleep 
    // following the same function call format described in i2c2.h
    I2C2_MasterWrite( WriteData, 3, slaveDeviceAddress, &status);  // Results in TRAPS_halt_on_error
...
}
#1

5 Replies Related Threads

    paulnotpaul
    Starting Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2017/01/25 07:53:34
    • Location: 0
    • Status: offline
    Re: I2C2_MasterWrite() function in i2c2.c always generates a TRAPS_halt_on_error 2017/02/25 19:41:43 (permalink)
    0
    Hi!
     
    I am also running into this issue with my I2C comms. My system works for a 10-20 mins then this error happens. 
     
    I also sometimes seem to get a full queue in mssp2_i2c_object.trStatus.s.full that my program can't seem to recover from. A reset fixes everything, so I'm not entire convinced that it's a hardware issue.
     
    Did you figure anything out with your issue?
     
    Thanks!
    #2
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3146
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: I2C2_MasterWrite() function in i2c2.c always generates a TRAPS_halt_on_error 2017/02/26 11:51:36 (permalink)
    0
    Probably a trap address error, he never said what it was.
    i2c doesn't contain a buffer to hold messages so it must be the software.
    #3
    paulnotpaul
    Starting Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2017/01/25 07:53:34
    • Location: 0
    • Status: offline
    Re: I2C2_MasterWrite() function in i2c2.c always generates a TRAPS_halt_on_error 2017/02/27 11:28:27 (permalink)
    3 (1)
    Thanks Gort!
     
    It is in fact an address error, the error code of 2 has that. Any tips of tracking down where it came from?
    #4
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3146
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: I2C2_MasterWrite() function in i2c2.c always generates a TRAPS_halt_on_error 2017/03/01 20:01:43 (permalink)
    3.5 (2)
    16bit address read at odd address.
    Your program or the library has bugs.
     
    You may be able to look at the stack to see where the return address is.
    Or set a global variable, set a no. in each function, check value at address trap.
    #5
    scroteau
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2008/11/07 08:25:31
    • Location: Woodstock, CT
    • Status: offline
    Re: I2C2_MasterWrite() function in i2c2.c always generates a TRAPS_halt_on_error 2019/07/23 08:50:16 (permalink)
    0
    Did you ever resolve this problem?
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5