How to update the code to convert and store uint16_t value into 4 Hex chars (including possible leading "0"s). The program should update
char *AT_Send = "AT$SlhLH\n"; // 9x
to
char *AT_Send = "AT$S04ED\n"; // 9x
I thought to use utoa() string function but it doesn't work with string declaration by pointer and it is ignoring leading "0"s. Maybe I should create own function for it to be able to send the final string to USART (IoT)
#define F_CPU 3333333 #include <avr/io.h> #include <xc.h> // F_CPU #include <util/delay.h> // _delay_ms() #include <stdlib.h> // utoa() #include <string.h> // volatile union u_type //Setup a Union { unsigned int IntVar; unsigned char Bytes[2]; } temp; char *AT_Send = "AT$SlhLH\n"; // 9x char *buffer = "0000"; //uint16_t Voltage = 1261; // 0x04ED, remark 12.61 Volts * 100, from ADC uint8_t n; int main(void) { temp.IntVar = 1261; // Voltage n = temp.Bytes[0]; // Just for variable watch utoa(temp.Bytes[0], buffer, 16); // Lo) utoa(temp.Bytes[1], buffer, 16); // Hi) while (1) { } }