Skip to main content
jtron.1
Associate II
September 21, 2022
Solved

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.

  • September 21, 2022
  • 4 replies
  • 4757 views

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.

This topic has been closed for replies.
Best answer by jtron.1

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.

4 replies

Tesla DeLorean
Guru
September 21, 2022

You've stated the symptoms twice, not sure that helps understand the cause.

Code is broken.

Show code.​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
jtron.1
jtron.1Author
Associate II
September 21, 2022

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.

 

Tesla DeLorean
Guru
September 21, 2022

PutVal function does not convert to a numeric value.

I​s this something you wrote or copied?

Perhaps rewrite so it does what it should.​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
jtron.1
jtron.1Author
Associate II
September 23, 2022

ohk got it.

I am going make changes as per our discussion and will let you know soon.

jtron.1
jtron.1Author
Associate II
September 23, 2022

As I am working keil and the below function but keil shows a warning

(warning: implicit declaration of function 'simple_decimal_string' is invalid in C99 [-Wimplicit-function-declaration])

  1. char *simple_decimal_string(unsigned int x) // convert 32-bit unsigned to decimal string
  2. {
  3. static char str[16]; // Enough to hold 10 digits and NUL
  4. char *s = str + sizeof(str);
  5.  
  6. *--s = 0; // NULL at end, working backward
  7. do
  8. {
  9. *--s = '0' + (x % 10);
  10. x /= 10;
  11. }
  12. while(x);
  13.  
  14. return(s);
  15. }

Then I started working on CUBE IDE.

In which I am facing a problem my code programmed in mcu but controller does not response like nothing burned in it.

I am using STM32F103C6 controller.

I am using ST-Link/V2 probe for programming.

Even I tried a simple blinky programme but it does not work.

I am using Debugger setting as OPEN OCD mode and software reset.

For led blinking I did following setting in CUBE MX.

Used SYS as serial wire

GPIO as output PC13 for led.

Using ext osc.

I wrote code simple for toggling led status.

HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);

HAL_Delay(500);

Tesla DeLorean
Guru
September 23, 2022

>>warning: implicit declaration of function 'simple_decimal_string' is invalid in C99 [-Wimplicit-function-declaration]

So you used the function earlier in the code than the definition/body of the code?

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
jtron.1
jtron.1AuthorBest answer
Associate II
September 24, 2022

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.