Magnetometer (model LIS2MDL) getting strange readings for not so high magnetic fields. What is going on?
As you can see in the picture, the higher part of the sinusoid signal is getting wrecked in the highest part, but it appears in the lower part (so the information is still there).
This happens when the magnetic field is strong enough (We are putting a coil next to it generating the magnetic field)
The problem is that I (and any of the people I work with) do not think this is a big enough magnetic field for it to overflow, so that is why we are wondering if there is another problem we did not think about.
As the manufacturer suggests, the data aquired by the magnetometer should be processed as following:

and what I am doing to process it in the code is exactly that:
uint8_t y_low = 0;
uint8_t y_high = 0;
//y_L
HAL_I2C_Mem_Read(&hi2c1,slave_address << 1, OUTY_L_REG, I2C_MEMADD_SIZE_8BIT, &y_low, size, HAL_MAX_DELAY);
//y_H
HAL_I2C_Mem_Read(&hi2c1,slave_address << 1, OUTY_H_REG, I2C_MEMADD_SIZE_8BIT, &y_high, size, HAL_MAX_DELAY);
y_value_plot = (int16_t)join_into_signed_16b(y_low, y_high, true); //<----- CAMBIAR A INT16_Twhere the function join_into_signed_16b does the following:
uint16_t join_into_signed_16b(uint8_t low_part, uint8_t high_part, bool convert_to_mg){
uint16_t signed_16b = (uint16_t)((high_part<<8)|low_part);
// if(convert_to_mg){
// signed_16b = (int16_t)((float)signed_16b * 1.5);
// }
return signed_16b;
}The resultant wave is "clipping" because the upper part of the Y register is not changing and remains all 8bit at 1.
Also as you can see, the concatenation is performed as expected.
Thank you very much in advance.
Ginés.
