这是一个函数。把它放在程序的顶部。当它正确运行时,您可以安全地删除它,确保您的 I2C 没有字节或字交换。
- /* --------------------------------------------------
- * --- This function can be used to test VL53L5CX I2C
- * --------------------------------------------------
- */
-
- uint8_t vl53l5cx_test_i2c(VL53L5CX_Configuration *p_dev){
- uint8_t status = VL53L5CX_STATUS_OK;
- printf("Starting VL53L5CX I2C test...n");
-
- /* To check the I2C RdByte/WrByte function :
- * Inside the function “vl53l5cx_is_alive()”, it will call I2C RdByte/WrByte to
- * read device and verion ID. which can help you to verify the I2C RdByte/WrByte
- * functions at same time.
- */
- uint8_t device_id, revision_id;
- status |= WrByte(&(p_dev->platform), 0x7fff, 0x00);
- status |= RdByte(&(p_dev->platform), 0, &device_id);
- status |= RdByte(&(p_dev->platform), 1, &revision_id);
- status |= WrByte(&(p_dev->platform), 0x7fff, 0x02);
-
- if(status)
- {
- printf("Error Rd/Wr byte: status %un", status);
- return status;
- }
-
- /* To check the I2C RdMulti/WrMulti function:
- * Below is example codes which can help you vefify the I2C RdMulti/WrMulti
- * function.
- */
-
- uint8_t Data_write[4]={0x5A,0xA5,0xAA,0x55};
- uint8_t Data_read[4]={0,0,0,0};
- uint8_t Data_default[4]={0,0,0,0};
-
- status |= RdMulti(&(p_dev->platform), 0x100, Data_default, 4);
- if(status)
- {
- printf("Error RdMulti: status %un", status);
- return status;
- }
-
- printf("Read default value and save it at beggingn");
- printf("Data_default (0x%x)n", Data_default[0]);
- printf("Data_default (0x%x)n", Data_default[1]);
- printf("Data_default (0x%x)n", Data_default[2]);
- printf("Data_default (0x%x)n", Data_default[3]);
-
- status |= WrMulti(&(Dev.platform), 0x100, Data_write, 4);
- if(status)
- {
- printf("Error WrMulti: status %un", status);
- return status;
- }
- printf("Writing values 0x5A 0xA5 0xAA 0x55n");
-
- status |= RdMulti(&(p_dev->platform), 0x100, Data_read, 4);
- if(status)
- {
- printf("Error RdMulti: status %un", status);
- return status;
- }
-
- printf("Reading:n");
- printf("Data_read (0x%x)n", Data_read[0]);
- printf("Data_read (0x%x)n", Data_read[1]);
- printf("Data_read (0x%x)n", Data_read[2]);
- printf("Data_read (0x%x)n", Data_read[3]);
-
-
- status |= WrMulti(&(Dev.platform), 0x100, Data_default, 4);
- printf("Write back default valuen");
- if(status)
- {
- printf("Error WrMulti: status %un", status);
- return status;
- }
-
- status |= RdMulti(&(Dev.platform), 0x100, Data_default, 4);
- if(status)
- {
- printf("Error RdMulti: status %un", status);
- return status;
- }
-
- printf("Read value again to make sure default value was correct loadedn");
- printf("Data_default (0x%x)n", Data_default[0]);
- printf("Data_default (0x%x)n", Data_default[1]);
- printf("Data_default (0x%x)n", Data_default[2]);
- printf("Data_default (0x%x)n", Data_default[3]);
-
- printf("I2C test done - everything works fine.n");
-
- return status;
- }
|
|
2022-12-15 11:27:34
评论
举报
|
|
|