- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Forum
As part of my project I would like to be able to read the output of a LIDAR sensor on a serial monitor over the I2C bus, using a PSoC 5LP. (Linked below)
http://www.st.com/content/ccc/resource/technical/document/datasheet/group3/b2/1e/33/77/c6/92/47/6b/D... (LIDAR datasheet)
I found a post that took the ardunio libraries and converted them to PSoC 4 libraries. (Linked below)
https://www.hackster.io/vlad-radoiu/measuring-distance-with-vl53l0x-tof-sensor-1080f1
I have the serial monitor part working however I cannot get the sensor to initiate. I had an printf after the initialization of each component (Timer and I2C block) showing the place where the program hangs. (picture attached)
Any help on whether this is a bug in my code or a hardware issue would be greatly appreciated.
Below is attached my workspace archive (Minimal) and an image of what is displayed in PuTTy
Thanks
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum.
Byte I2C interface is quite simple: After setting up the component and starting it you use
I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE); // Initialize a transaction for writing
I2C_MasterWriteByte(Register); // Indicate which register you want to write to
I2C_MasterWriteByte(Value); // Write to register
I2C_MasterSendStop(); // End of transaction
When you want to read from a device you use (example for reading two bytes
I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE); // Initialize a transaction for writing
I2C_MasterWrite(Register); // Indicate which register you want to write to
I2C_MasterSendRestart(DeviceAddress,I2C_READ_XFER_MODE);
I2C_MasterReadByte(I2C_ACK_DATA); // Read from register
I2C_MasterReadByte(I2C_NAK_DATA); // Read from register, last byte is NAKed
I2C_MasterSendStop(); // End of transaction
Not too difficult. Keep in mind that most of the APIs (except those for reading a byte) return a status byte which, when non-zero indicate an error condition.
The high-level APIs must be used in this way:
Writing to slave Count bytes
I2C_MasterWriteBuf(SlaveAddress,DataPtr,Count,I2C_MODE_COMPLETE_XFER);
Reading from Slave sending register/command byte first:
I2C_MasterWriteBuf(SlaveAddress,&RegAddress,1,I2C_MODE_NO_STOP);
I2C_MasterReadBuf(SlaveAddress,DataPtr,Count,I2C_MODE_REPEAT_START);
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bob
Thanks for the quick reply, will try out what you suggested
Ben
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Forum,
I am working on this project and try to change my sensor address but i cant change it, because i need to connect another sensor in same I2C bus, so i need to change the default address 0x29.
I am using the same code from the link
Measuring distance with VL53L0X ToF sensor - Hackster.io
any one can help me to understand how i will change my sensor default address ? I already try to reach out my sensor forum POLOlU , but they reply me they reply me this (we are not familiar enough with your microcontroller platform to offer detailed advice about working with it. )
Thanks for your cooperation,
Md. Asif Reza.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi.
I know this reply is so late and I guess it's not going to help you anymore, but maybe it's of use for anyone else interested in this topic.
In order to obtain correct behaviour for PSoC 5 devices, you've got to go into VL53L0X.c and comment every call to I2C_I2CMasterClearStatus() from the READ functions (all READ functions; 3-4 functions, all calls to that clear_status API should be commented out).
// Read an 8-bit register
uint8_t VL53L0X_readReg(uint8_t reg)
{
uint8_t data[4];
uint8_t value = 0;
last_status = I2C_I2CMasterSendStart( (uint32_t)VL53L0X_address, I2C_I2C_WRITE_XFER_MODE );
if( I2C_I2C_MSTR_NO_ERROR == last_status )
{
last_status = I2C_I2CMasterWriteByte( (uint32_t)reg );
if( I2C_I2C_MSTR_NO_ERROR == last_status )
{
// I2C_I2CMasterClearStatus(); //This one!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
last_status = I2C_I2CMasterReadBuf( (uint32_t)VL53L0X_address, data, 01u, I2C_I2C_MODE_REPEAT_START);
for(;;)
{
if(0u != (I2C_I2CMasterStatus() & I2C_I2C_MSTAT_RD_CMPLT))
{
/* Transfer complete. Check Master status to make sure that transfer
completed without errors. */
break;
}
}
}
else
I2C_I2CMasterSendStop();
}
else
I2C_I2CMasterSendStop();
value = data[0];
return value;
}
That function causes the Init() function to hang (in fact, it causes the read functions to hang, but the Init function, which calls some of the read functions, is the first place you can see the unwanted behaviour happen).
I didn't manage to determine why this is the case as of now, but I'll be back with another reply when I do. Strangely enough, the unwanted behavior doesn't appear on PSoC 4 devices, only on PSoC 5. Anyway, this should be a quick fix.
Costi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This helped me today. Thank you.