cancel
Showing results for 
Search instead for 
Did you mean: 

SSD1306 stop working while DMA Mode enabled to read ADC.

asking
Associate II

I am trying to read 4-20mA Transducer using ADC and DMA Enabled. Normally OLED works fine.

 

But when i enabled DMA, OLED is blank. What could be wrong ?

 

 

 

int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_I2C1_Init();
  MX_ADC1_Init();
  /* USER CODE BEGIN 2 */

  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_buf, ADC_BUF_LEN);  // start the adc in dma mode


  ssd1306_Init();
   // here value is the buffer, where the adc values are going to store
   // 3 is the number of values going to store == no. of channels we are using


  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
	//  HAL_ADC_Start_DMA(&hadc1, value, 2);  // start the adc in dma mode
	//ssd1306_TestFPS();
	//ssd1306_TestAll();
	//  ssd1306_TestFonts22();
	  // Example loop to demonstrate the counter increment
	    for (int i = 0; i < 1000; i++) {
	    //	adc1x = value[0];
	        ssd1306_TestFonts22(); // Display the current counter value
	        incrementCounter(); // Increment the counter
	       // HAL_Delay(50);
	    }
  }
  /* USER CODE END 3 */
}


void ssd1306_TestFonts22() {
#ifdef SSD1306_INCLUDE_FONT_16x24
    uint8_t x1, y1, x2, y2;

    // Convert the float counter value to a string
   // char counter_str[6]; // Assuming the format is XX.XX
   // snprintf(counter_str, 5, "%2.2f", counter);

    char float_str[10]; // Assuming the format is XX.XX
        snprintf(float_str, 10, "%02.2f" "%%rH", counter);

     //   char decimal_str[10]; // Assuming the format is XX.XX
            //    snprintf(decimal_str, 10, "%4d", adc1x);

    ssd1306_Fill(Black);

    // Display the counter value
    ssd1306_SetCursor(0, 4);
    ssd1306_WriteString(float_str, Font_16x24, White);

    // Other text
 //   ssd1306_SetCursor(0, 4+24+8);
  //  ssd1306_WriteString(decimal_str, Font_16x24, White);

    // Underline
    x1 = 6*16;
    y1 = 4+24+8+24;
    x2 = x1+16;
    y2 = y1+2;
    ssd1306_FillRectangle(x1, y1, x2, y2, White);

    ssd1306_UpdateScreen();
#endif
}

 

 

 

 
1 REPLY 1
AScha.3
Chief III

>But when i enabled DMA, OLED is blank. What could be wrong ?

Something in your program...!  :)

 

Check where DMA is writing to and size of target area - really in the array you set ?

 

btw

I made a small DSO , using F103 + SSD1306 ; no problems . Used u8g lib (see on github).

If you feel a post has answered your question, please click "Accept as Solution".