I have written the following piece of code to write the value '9' as an integer to, and read from, the 24LC512 EEPROM.
uint8_t dataByteIn = 0x39;
uint8_t dataByteOut = 0;
To write:
HAL_I2C_Mem_Write(&hi2c1,(0x50 << 1), 0x00, I2C_MEMADD_SIZE_16BIT, &dataByteIn, 1, 1000);
To read:
HAL_I2C_Mem_Read(&hi2c1, (0x50 << 1), 0x00, I2C_MEMADD_SIZE_16BIT, &dataByteOut, 1, 1000);
I have no issue with reading or writing itself, but the actual representation of the values after reading is baffling to me. The reason dataByteIn
is 0x39 (the hex value for the decimal value '9'), is because I've found its the only way to write and read back decimal numbers. What I'm trying to achieve is initialise the data I want to write, as an uint8_t
in its decimal value i.e. uint8_t dataByteIn = 9;
, then read it back as '9'. How would I achieve this?
I am reading the value on a serial terminal using USART:
HAL_UART_Transmit(&huart3, &dataByteOut, sizeof(dataByteOut), 1000);