Other Parts Discussed in Thread: IWR6843ISK
Hi,
I am trying to modify the 3D_people_count_6843_mss project so that I can communicate with the sensor via I2C in slave mode.
I've added this in the MmwDemo_uartTxTask function:
I2CSlave_Handle i2cHandle; I2CSlave_Params i2cParams; bool retVal = false; int32_t errCode = 0; uint32_t arg; uint8_t rxData[100]; uint8_t txData[100]; Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINF13_PADAH, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR68XX_PINF13_PADAH, SOC_XWR68XX_PINF13_PADAH_I2C_SDA); Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PING14_PADAI, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR68XX_PING14_PADAI, SOC_XWR68XX_PING14_PADAI_I2C_SCL); /* Reset the transmit and receive buffer */ memset(&rxData, 0, sizeof (rxData)); /* Initialize the I2C Slave driver */ I2CSlave_init(); /* Initialize the I2C driver default parameters */ I2CSlave_Params_init(&i2cParams); i2cParams.transferMode = I2CSLAVE_MODE_BLOCKING; i2cParams.slaveAddress = 0x48; /* Open the I2C Slave driver */ i2cHandle = I2CSlave_open(0, &i2cParams); char hak[20] = "what?"; if (i2cHandle == NULL) { strcat(hak, "NULL"); //System_printf ("Error: I2C Driver Open failed\n"); //return -1; } System_printf ("Debug: I2C Slave Open passed\n"); arg = 1; errCode = I2CSlave_control (i2cHandle, I2C_CMD_ADDR_MODE, (void* )&arg);
and added the blocking line:
txData[0] = 0x69; I2CSlave_read_write(i2cHandle, rxData, txData, 1); // Wait for master's poke and send the number of bytes to be transferred next
I've connected the SDA and SCK lines to my MCU based on this (4.7kΩ pull-ups connected):
Here's the full function which is the only part I have modified so far:
/** @brief Transmits detection data over UART * * @param[in] uartHandle UART driver handle * @param[in] result Pointer to result from object detection DPC processing * @param[in] timingInfo Pointer to timing information provided from core that runs data path */ void MmwDemo_uartTxTask(UArg arg0, UArg arg1) /*static void Pcount3DDemo_transmitProcessedOutput ( UART_Handle uartHandle, Pcount3DDemo_output_message_UARTpointCloud *result, uint32_t frameIdx, uint8_t subFrameIdx, Pcount3DDemo_output_message_stats *timingInfo )*/ { UART_Handle uartHandle; MmwDemo_output_message_header header; uint32_t tlvIdx = 0; uint32_t packetLen, subFrameIdx, frameIdx; MmwDemo_output_message_stats *timingInfo; MmwDemo_output_message_compressedPointCloud_uart *objOut; uint32_t targetListLength=0, targetIndexLength=0, presenceIndLength=0, targetHeightLength=0; volatile uint32_t startTime; MmwDemo_output_message_tl tl; /* Clear message header */ memset((void *)&header, 0, sizeof(MmwDemo_output_message_header)); /* Header: */ header.platform = 0xA6843; header.magicWord[0] = 0x0102; header.magicWord[1] = 0x0304; header.magicWord[2] = 0x0506; header.magicWord[3] = 0x0708; header.version = MMWAVE_SDK_VERSION_BUILD | (MMWAVE_SDK_VERSION_BUGFIX << 8) | (MMWAVE_SDK_VERSION_MINOR << 16) | (MMWAVE_SDK_VERSION_MAJOR << 24); /* wait for new message and process all the messages received from the peer */ while(1) { uint32_t numTargets, numIndices; uint8_t *tList; uint8_t *tIndex; uint8_t *tHeight; Semaphore_pend(gMmwMssMCB.uartTxSemHandle, BIOS_WAIT_FOREVER); startTime = Cycleprofiler_getTimeStamp(); tlvIdx = 0; uartHandle = gMmwMssMCB.loggingUartHandle; objOut = &(gMmwMssMCB.pointCloudToUart); subFrameIdx = gMmwMssMCB.currSubFrameIdx; timingInfo = &gMmwMssMCB.subFrameStats[subFrameIdx].outputStats; frameIdx = gMmwMssMCB.frameStatsFromDSP->frameStartIntCounter; packetLen = sizeof(MmwDemo_output_message_header); numTargets = gMmwMssMCB.numTargets; numIndices = gMmwMssMCB.numIndices; tList = (uint8_t*)gMmwMssMCB.trackerOutput.tList[gMmwMssMCB.trackerOutput.currentDescr]; tIndex = (uint8_t*)gMmwMssMCB.trackerOutput.tIndex[gMmwMssMCB.trackerOutput.currentDescr]; #ifdef HEIGHT_DETECTION_ENABLED tHeight = (uint8_t*)gMmwMssMCB.trackerOutput.tHeight[gMmwMssMCB.trackerOutput.currentDescr]; #endif if (objOut->header.length > 0) { packetLen += sizeof(MmwDemo_output_message_tl) + objOut->header.length; tlvIdx++; } if (numTargets > 0) { targetListLength = numTargets*sizeof(trackerProc_Target); packetLen += sizeof(MmwDemo_output_message_tl) + targetListLength; tlvIdx++; } if ((numIndices > 0) && (numTargets > 0)) { targetIndexLength = numIndices*sizeof(trackerProc_TargetIndex); packetLen += sizeof(MmwDemo_output_message_tl) + targetIndexLength; tlvIdx++; } #ifdef HEIGHT_DETECTION_ENABLED if (numTargets > 0) { targetHeightLength = numTargets*sizeof(heightDet_TargetHeight); packetLen += sizeof(MmwDemo_output_message_tl) + targetHeightLength; tlvIdx++; } #endif if(gMmwMssMCB.presenceDetEnabled) { presenceIndLength = sizeof(uint32_t); packetLen += sizeof(MmwDemo_output_message_tl) + presenceIndLength; tlvIdx++; } header.numTLVs = tlvIdx; header.totalPacketLen = packetLen; header.frameNumber = frameIdx; header.subFrameNumber = subFrameIdx; header.numDetectedObj = gMmwMssMCB.numDetectedPoints; // haki I2CSlave_Handle i2cHandle; I2CSlave_Params i2cParams; bool retVal = false; int32_t errCode = 0; uint32_t arg; uint8_t rxData[100]; uint8_t txData[100]; Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINF13_PADAH, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR68XX_PINF13_PADAH, SOC_XWR68XX_PINF13_PADAH_I2C_SDA); Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PING14_PADAI, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); Pinmux_Set_FuncSel(SOC_XWR68XX_PING14_PADAI, SOC_XWR68XX_PING14_PADAI_I2C_SCL); /* Reset the transmit and receive buffer */ memset(&rxData, 0, sizeof (rxData)); /* Initialize the I2C Slave driver */ I2CSlave_init(); /* Initialize the I2C driver default parameters */ I2CSlave_Params_init(&i2cParams); i2cParams.transferMode = I2CSLAVE_MODE_BLOCKING; i2cParams.slaveAddress = 0x48; /* Open the I2C Slave driver */ i2cHandle = I2CSlave_open(0, &i2cParams); char hak[20] = "what?"; if (i2cHandle == NULL) { strcat(hak, "wdad"); //System_printf ("Error: I2C Driver Open failed\n"); //return -1; } System_printf ("Debug: I2C Slave Open passed\n"); arg = 1; errCode = I2CSlave_control (i2cHandle, I2C_CMD_ADDR_MODE, (void* )&arg); //I2CSlave_close(i2cHandle); // hako while (1) { /* Send packet header */ UART_write (uartHandle, (uint8_t*)&header, sizeof(MmwDemo_output_message_header)); UART_write (uartHandle, (uint8_t*)hak, strlen(hak)); txData[0] = 0x69; // haki &header.totalPacketLen I2CSlave_read_write(i2cHandle, rxData, txData, 1); // Wait for master's poke and send the number of bytes to be transferred next // I2CSlave_write(i2cHandle, , header.totalPacketLen); // hako } /* Send detected Objects */ if (objOut->header.length > 0) { UART_write (uartHandle, (uint8_t*)objOut, objOut->header.length + sizeof(MmwDemo_output_message_tl)); } Task_sleep(1); /*Send Tracker information*/ if (numTargets > 0) { tl.type = MMWDEMO_OUTPUT_MSG_TRACKERPROC_3D_TARGET_LIST; tl.length = targetListLength; UART_write(uartHandle, (uint8_t*)&tl, sizeof(MmwDemo_output_message_tl)); UART_write(uartHandle, tList, targetListLength); GPIO_toggle(gMmwMssMCB.cfg.platformCfg.SensorStatusGPIO); /* Send Target Height TLV if enabled*/ #ifdef HEIGHT_DETECTION_ENABLED tl.type = MMWDEMO_OUTPUT_MSG_TRACKERPROC_TARGET_HEIGHT; tl.length = targetHeightLength; UART_write(uartHandle, (uint8_t*)&tl, sizeof(MmwDemo_output_message_tl)); UART_write(uartHandle, tHeight, targetHeightLength); #endif } /*Send Tracker Index Information*/ if ((numIndices > 0) && (numTargets > 0)) { tl.type = MMWDEMO_OUTPUT_MSG_TRACKERPROC_TARGET_INDEX; tl.length = targetIndexLength; UART_write(uartHandle, (uint8_t*)&tl, sizeof(MmwDemo_output_message_tl)); UART_write(uartHandle, tIndex, targetIndexLength); } /* Send Presence TLV if presence detect is enabled */ if(gMmwMssMCB.presenceDetEnabled) { tl.type = MMWDEMO_OUTPUT_MSG_PRESCENCE_INDICATION; tl.length = presenceIndLength; UART_write(uartHandle, (uint8_t*)&tl, sizeof(MmwDemo_output_message_tl)); UART_write(uartHandle, (uint8_t*)&(gMmwMssMCB.presenceInd), sizeof(uint32_t)); } gMmwMssMCB.uartProcessingTimeInUsec = (Cycleprofiler_getTimeStamp() - startTime)/R4F_CLOCK_MHZ; } }
Slave address is 0x48 and so the byte transmitted in the I2C message is 0x91.
So in short, I initialize the I2C parameters and then wait for an I2C message from the master (my MCU). After I give the message I receive a NACK signal from the sensor however.
Is there something obvious that I am doing wrong?
thanks