2019-01-06 04:35 PM
Hello everyone,
I’m working with an MCU STM32F401 (NUCLEO Board) which receives via I2C the measurements sent by a sensor VL53L1. I would like then to be able to intervene at any time by interrupting the communication between the MCU and the sensor to change certain sensor’s parameters such as timmingbudget, ROI (region of interest) etc or simply stop and restart the measurement. For this I’m using the MCU as a bridge between the PC and the sensor. The PC will send the data via I2C to the MCU and the MCU in an interrupt routine will pass the received data as a parameter by calling the functions of the Vl53l1. I want those data to be written in registers.
My question is how to create addresses for these registers in the MCU’s memory. I read on several forums that simple #define can create registers in the memory of the MCU. Do you think there are other things to consider?
Thank you all.
PS: i'm using HAL library.
2019-01-06 07:33 PM
It depends on how often adjustments are needed, and how many registers can be updated by the programmer "live".
Personnaly, for easier debug, I try to replace #define by enums
For debugging remote sensors, there are simple tricks which must be carefully used
Trick 1: Create an array of bytes which will be the cloned copy of what's in the remote device.
Trick 2: From the main loop, regularly read and copy all the remote registers and update the buffer.
Warning: Sometime you have to make multiple block reads to avoid FIFO zones for example.
Trick 3: Using a volatile variable to make a debug only accessible code which will write back from array to remote sensors some of the control registers you want to be able to modify.
volatile uint8_t update = 0;
(...)
if(update) { update=0; RAMtoRemoteSensorWriteRegs()...// here you write back to sensor some of the registers from the buffer. If they are unmodified, nothing should happen
Now run the code. and stop/breakpoint just after reading the registers: The byte array gives you a snapshot of the registers value. If you manually change update to 1 and modify manually some of the register values in the array, the code will branch to write back the modifications to the sensor.
Using enums, unions and structs, you can debug view the sensor as raw of data, or struct of bytes with registers name visible for easy browsing when there are many of them.
That's one way to avoid building up a console, and provides you a debug mean which only activates with debugger.
2019-01-07 04:10 AM
Thank you for your answer. i will try to do something following your suggestion and i'll be back if get some issues.
thank you !