Microchip
直播中

陈舒斌

7年用户 218经验值
私信 关注
[问答]

I2C2_MasterWrite()函数总是生成TRAPS_._on_error该怎么办?

我正在使用MCC生成的代码,用于我的原型板上的DSPIC33 EP64 GP502处理器。问题是I2C2_MasterWrite()函数总是生成TRAPS_._on_error,在下面的函数中值为2:void_.((na.,noreturn,.))TRAPS_._on_error(uint16_t代码){TRAPS_error_code=code;...MCC生成文件mcc.c和i2c2.c,等等,这启发了我使用I2C2SmithWrreWrand()函数。谁能帮我弄清这个陷阱的原因?我用Google找不到任何信息来理解TRAPS_._on_error的错误。我用示波器使用标准的_LATB14和_LATB15函数用位脉冲实现来验证I2C时钟和SDA信号的信号完整性,并且看到SDA和SCL信号随着程序摇摆。阿默德但是,使用MCC生成的函数,这些相同的信号甚至没有摆动。我验证我正在交谈的从设备(PCA9685)是使用启用信号上的示波器启用的。产生错误的相关代码如下所示,main(void){//初始化设备SYSTEM_In(); //*指定为输出*/_TRISB1=0;//RB1_TRISB4_TRISB4=0;//RB4_TRISB4 13131313131313130;//RB4_RB4_TRISB13 131313131313131313131313131313131313131313130;//RB14_TRISB14_TRISB15131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131316PCA9685_PCA9685_TRISB15=0;////RB14_TRISB1414141414141414131313131313131313131313131313阿里OSCILLATOR_Initialize();OSCILLATOR_Initialize();UART2_Initialize();SPI1_Initialize();UART1_Initiitialize();I2C2_Initialize();I2C2_III2C2_初始化();EXT_INT_INT_InInitialize();TMR1_Initialize_Initialize();TMR1_Initialize_Initialize();INTERRUPT_InInitialize(;INTERRUPUPUPUPUPUPT_GlobalEnEnEnEnEnEn();INTERRUPUPUPUPUPUPUPUPUPUPUPUPUPT_TTTTTTTTTTTTTTE_GlobalEnEnEnEn_STATUS状态=I2C2_MESSAGE_PENDING;uint16_t从设备地址=SLAVE_DEV_ADDRESS;WriteData[0]=(MODE1>8);//PCA9685子地址WriteData[1]=(uint8_t)(MODE1);WriteData[2]=0b00110001;//按照i2c2.h I2C2_MasterWriteData中描述的相同函数调用格式将模式设置为.//,3,SLaveDeVice地址,和状态);//结果在TrrspHaltTynOnLoad…}中的结果

以上来自于百度翻译


      以下为原文

    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
...
}

更多回帖

发帖
×
20
完善资料,
赚取积分