2022-09-21 01:23 AM
Hi team! I am working on the OLED interfacing with STM32F103C8T6. All I want to do that is to display the counter value from 0 to 255 on OLED. But when I simply put the random number such as 48 it shows its equivalent ASCII value not a decimal value as it is 48.
What is the reason of it?
I am delighted to ST community for the help.
Thanks in advance.
Solved! Go to Solution.
2022-09-23 10:19 PM
Hi DeLorean.!
I am very happy to say that my code is working now.
Thank you so much tesla. This happens only with your guidance.
I also thanks to ST community for this platform.
Grateful.....!!!!!!!!!!!
Thanks a lot tesla again.
Actually I was declaring function body/definition not in the same file.
However, it is working.
2022-09-21 02:23 AM
You've stated the symptoms twice, not sure that helps understand the cause.
Code is broken.
Show code.
2022-09-21 02:48 AM
Thanks for the reply tesla.
Actually the problem is OLED shows ASCII value of decimal equivalent.
Below is the code
//This function put the value that we want to display in my case i is the int and i=5(val) lets say
int SSD1306_PutVal(int val, FontDef_t* Font, SSD1306_COLOR_t color) {
/* Write characters */
while (val) {
/* Write character by character */
if (SSD1306_PutV1(val, Font, color) != val) {
/* Return error */
return val;
}
/* Increase string pointer */
val++;
}
/* Everything OK, zero should be returned */
return val;
}
//This function decide its Height and Width
int SSD1306_PutV1(int ch, FontDef_t* Font, SSD1306_COLOR_t color) {
uint32_t i, b, j;
/* Check available space in LCD */
if (
SSD1306_WIDTH <= (SSD1306.CurrentX + Font->FontWidth) ||
SSD1306_HEIGHT <= (SSD1306.CurrentY + Font->FontHeight)
) {
/* Error */
return 0;
}
/* Go through font */
for (i = 0; i < Font->FontHeight; i++) {
b = Font->data[(ch - 32) * Font->FontHeight + i];
for (j = 0; j < Font->FontWidth; j++) {
if ((b << j) & 0x8000) {
SSD1306_DrawPixel(SSD1306.CurrentX + j, (SSD1306.CurrentY + i), (SSD1306_COLOR_t) color);
} else {
SSD1306_DrawPixel(SSD1306.CurrentX + j, (SSD1306.CurrentY + i), (SSD1306_COLOR_t)!color);
}
}
}
/* Increase pointer */
SSD1306.CurrentX += Font->FontWidth;
/* Return character written */
return ch;
}
void SSD1306_UpdateScreen(void) {
uint8_t m;
for (m = 0; m < 8; m++) {
SSD1306_WRITECOMMAND(0xB0 + m); //Set Page Start
//Address for Page
//Addressing Mode
SSD1306_WRITECOMMAND(0x00);
SSD1306_WRITECOMMAND(0x10);
/* Write multi data */
ssd1306_I2C_WriteMulti(SSD1306_I2C_ADDR, 0x40, &SSD1306_Buffer[SSD1306_WIDTH * m], SSD1306_WIDTH);
}
}
void ssd1306_I2C_WriteMulti(uint8_t address, uint8_t reg, uint8_t* data, uint16_t count) {
uint8_t dt[256];
dt[0] = reg;
uint8_t i;
for(i = 0; i < count; i++)
dt[i+1] = data[i];
HAL_I2C_Master_Transmit(&hi2c1, address, dt, count+1, 10);
}
//All the functions used below already described above
int i;
i=48;//When I put this value OLED shows its equivalent ASCII vale from 0123456789:
SSD1306_GotoXY (0,0);// //function is above described
SSD1306_PutVal ( i, &Font_11x18, 1);// //function is above described
SSD1306_UpdateScreen(); //function is above described
HAL_Delay (1000);
Thanks in advance.
2022-09-21 03:06 AM
PutVal function does not convert to a numeric value.
Is this something you wrote or copied?
Perhaps rewrite so it does what it should.
2022-09-21 03:11 AM
Yes copied code from google.
The person was showing Hello world.
I just make one change in it.
I make it int and removed pointer.
Below is the original function of PutVal()
char SSD1306_Puts(char* str, FontDef_t* Font, SSD1306_COLOR_t color) {
/* Write characters */
while (*str) {
/* Write character by character */
if (SSD1306_Putc(*str, Font, color) != *str) {
/* Return error */
return *str;
}
/* Increase string pointer */
str++;
}
/* Everything OK, zero should be returned */
return *str;
}
2022-09-21 04:57 AM
Create a string using itoa() or decompose to digits using basic math.
2022-09-21 05:16 AM
ok any link or application??
2022-09-21 08:00 AM
This line of code explain all
b = Font->data[(ch - 32) * Font->FontHeight + i];
and you need understand font func show one character by code not numbers.
Puts prints every characters in string over cycle...usw
2022-09-21 10:08 AM
>>ok any link or application??
This is basic C programming and math, surely?
char string[16];
sprintf(string,"%d", val);
SSD1306_Puts (string, &Font_11x18, 1);
SSD1306_Puts (itoa(val, string, 10), &Font_11x18, 1);
char *simple_decimal_string(unsigned int x) // convert 32-bit unsigned to decimal string
{
static char str[16]; // Enough to hold 10 digits and NUL
char *s = str + sizeof(str);
*--s = 0; // NULL at end, working backward
do
{
*--s = '0' + (x % 10);
x /= 10;
}
while(x);
return(s);
}
SSD1306_Puts (simple_decimal_string(val), &Font_11x18, 1);
2022-09-22 09:05 PM
Sorry for my not availability.
Yes I will implement it today.