Dear Renesas Support Team,
We are currently working with the RH850/D1M1A (R7F701441) MCU to interface an ALS sensor (VEML6030) using RIIC communication as part of our custom cluster development board.
We are encountering an issue when attempting to read data from the ALS sensor using command 0x04. The sensor consistently returns a value of zero. To investigate, we utilized the Analog Discovery 2 logic analyzer to decode the RIIC frames.
0x04
We have attached the following for your reference:
1.The I²C read frame format from the VEML6030 datasheet.
2.The corresponding read sequence captured from the RH850 MCU.
3.Our current implementation code.
According to the sensor datasheet, after sending the slave address and command code, a repeated start condition must be issued before reading data. However, when we attempt to issue this repeated start, the MCU halts during the data reception phase inside the function:
my_iic_err = R_RIIC_receive_from_slave8b(0, (0x48<<1),0x00, my_rx_arr, 2); if(my_iic_err != R_RIIC_ERR_OK) { while(1); } data_LSB = my_rx_arr[0]; data_MSB = my_rx_arr[1]; als_val = (uint16_t)((data_MSB << 8) | data_LSB); static const r_dev_PinConfig_t my_iic1_PinConfig[] = /* Port Pin Func Dir Feedback Pull OpenDrain HiCurr HiSpeed InputType */ { /* RIIC unit 1 (on P3); SDA --> P3_0 , SCL --> P3_1 (data and clock) */ {3u, 0u, 1u, R_DEV_PIN_OUT, 1u, R_DEV_PIN_PULLNO, 1u, 0u, 0u, R_DEV_PIN_SCHMITT4}, {3u, 1u, 1u, R_DEV_PIN_OUT, 1u, R_DEV_PIN_PULLNO, 1u, 0u, 0u, R_DEV_PIN_SCHMITT4}, /* delimiter - do not remove */ {0u, R_DEV_PIN_LAST,0u,R_DEV_PIN_OUT,0u,R_DEV_PIN_PULLNO, 0u, 0u, 0u, R_DEV_PIN_CMOS1} }; void my_IIC1_Init(void) { //-------------------- IIC related -------------------------------------------------------- // Config IIC port pins EEPROM R_DEV_PinInit(my_iic1_PinConfig); my_iic_config.Baudrate = 100u * 1000u; my_iic_err = R_RIIC_Init(0,&my_iic_config); if(my_iic_err != R_RIIC_ERR_OK) { while(1); } } r_riic_Error_t R_RIIC_receive_from_slave8b(uint32_t Unit, uint8_t SlaveAddress, uint8_t InternalAddress, uint8_t *Rdata, uint32_t Size) { uint8_t index; uint8_t data; uint8_t tmp; r_riic_Error_t ack; uint32_t base; /* only 1 or 2 byte can be read */ if ((Size == 0) || (Size > 2)) { return R_RIIC_ERR_NG; } /* index for the read data buffer pointer */ index = 0; /* transmit in master mode */ R_RIIC_Master_start_condition(Unit); /* send the slave address */ data = SlaveAddress; ack = R_RIIC_Slave_address_send(Unit, &data); /* send the MSB internal address */ data = InternalAddress & 0xFFu; R_RIIC_data_send(Unit, &data); /* repeated start condition */ R_RIIC_Master_stop_condition(Unit, &data); //new // R_RIIC_Master_restart_condition(Unit); /* transmit in master mode */ R_RIIC_Master_start_condition(Unit); //new // R_RIIC_Master_readstart_condition(Unit); data = SlaveAddress + 1; /* Slave Address + 1 for read */ base = r_riic_Dev[Unit].BaseAddr; while((R_RIIC_READ_REG(8, (base + R_RIIC_SR2)) & R_RIIC_SR2_TDRE) == 0u) { /* Waiting TDRE empty */ } R_RIIC_WRITE_REG(8, (base + R_RIIC_DRT), data); /* send data */ while((R_RIIC_READ_REG(8, (base + R_RIIC_SR2)) & R_RIIC_SR2_RDRF) == 0u) { /* Waiting receive */ } if((R_RIIC_READ_REG(8, (base + R_RIIC_SR2)) & R_RIIC_SR2_NACKF) == 0u) { ack = R_RIIC_ERR_OK; } else { ack = R_RIIC_ERR_NG; } if(ack == R_RIIC_ERR_OK) { /* set wait = 1 */ tmp = R_RIIC_READ_REG(8, (base + R_RIIC_MR3)); R_RIIC_WRITE_REG(8, (base + R_RIIC_MR3), (tmp | 0x40u)); /* dummy read */ R_RIIC_READ_REG(8, (base + R_RIIC_DRR)); while((R_RIIC_READ_REG(8, (base + R_RIIC_SR2)) & R_RIIC_SR2_RDRF) == 0u) { } /* do an extra read byte if required */ if(2 == Size) { /* receive data read */ Rdata[index] = R_RIIC_READ_REG(8, (base + R_RIIC_DRR)); index++; while((R_RIIC_READ_REG(8, (base + R_RIIC_SR2)) & R_RIIC_SR2_RDRF) == 0u) { } } /* set RDRFS=1 */ tmp = R_RIIC_READ_REG(8, (base + R_RIIC_MR3)); R_RIIC_WRITE_REG(8, (base + R_RIIC_MR3), (tmp | 0x20u)); /* set ACKBT=1 */ tmp = R_RIIC_READ_REG(8, (base + R_RIIC_MR3)); R_RIIC_WRITE_REG(8, (base + R_RIIC_MR3), (tmp | 0x08u)); /* receive data read */ Rdata[index] = R_RIIC_READ_REG(8, (base + R_RIIC_DRR)); index++; while((R_RIIC_READ_REG(8, (base + R_RIIC_SR2)) & R_RIIC_SR2_RDRF) == 0u) { } } R_RIIC_Master_stop_condition(Unit, &data); return ack; }
Hello,
Have you check the I2C bus with an oscilloscope ? If the sensor returns with 0, the issue seems to be related with how the sensor is configured.