2019-09-23 08:19 PM
Hi guys ! I’m in a bit of a pickle so I finally decided to ask ..
I’m using a Dragino sensor node based on STM32. I need to change the default software to be able to read an I2C pressure WNK sensor. I know the sensor’s address is 0x6D. I also know that the registers I need to read are 06,07 and 08. I’m happy for now to read just the first 2(06 and 07).
The default programming uses HAL_I2C_*** library and I have tried everything I could think of to read these registers. I am using a uint8_ t txdata[1]={0x06} to initialise and set the pointer to the first register and an uint8_t rxdata[2] to read the content of the register. I feel really dumb right now to be honest so any suggestion would be greatly appreciated.
I am writing this from my phone hence the missing code.. but I’m happy to share the code once I am back in front of my computer.
Thank you in advance for any ideas!
Nick
2019-09-23 10:37 PM
Why not read byte by byte calling the function 3 times with the write sub address incrementally?
Also you should make sure the bus has pull up resistors and the sensor is really pure i2c. Some sensors want their multibyte read in a single transaction to work, then read 3 bytes in one function call...
2019-09-24 01:26 AM
The idea is great.. I was about to try this today.. I guess the first step is to make sure that the HAL_I2C function is written correctly. This is where i doubt myself..
Here is what I have:
HAL_I2C_Master_Transmit(&I2cHandle1,0x6D,txdata,1,5000);
HAL_I2C_Master_REceive)&I2cHandle1,0x6D,rxdata,2,5000);
Now, I know there will be questions about the parameters:
Here is the bit for the txdata and rxdata:
uint8_t txdata[1]={0x06};
uint8_t rxdata[2];
The I2Chandle1 is defined earlier in the code with all the parameters: instance, timing, addressmode, etc. I am wondering if that is an issue as well and if there is a more certain way or a better way of defining the mode to make it easier to fault find.
And yes, the sensor is pure I2C.. I was able to individually read the registers with a much simpler code on an Arduino Uno board. I uses that for testing purposes.. but my deployment is on this Dragino node.