1
\$\begingroup\$

I am trying to use Max14921(Battery monitoring system) to measure voltages of 16 cells of a battery pack. I have used stm32f103c8t6 as mcu. The problem is that I could never communicate with IC. I have checked pins and logic levels.I may not implement voltage readout progress truly.

This partshows how I configured SPI.

  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_MASTER;
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT;
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi1.Init.CRCPolynomial = 10;

And this is my 24bitspi transfer function

void SPI_Transfer24bit(uint8_t data1,uint8_t data2,uint8_t data3)
{

      uint8_t spi_data[3]={data1,data2,data3};

      HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4,GPIO_PIN_RESET);  // Chip is driven low while SPI transfer

      HAL_Delay(10); //Little delay prepares spi transfer to communicate properly        
      HAL_SPI_Transmit(&hspi1,spi_data,3,1000);

      HAL_Delay(10);

      HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4,GPIO_PIN_SET);  // Chip is driven high when SPI transfer done 

}

And This is How I try to measure cells.

void MeasureCell(uint8_t cell_number,uint16_t *cell_voltage)
{
      HAL_ADC_Start(&hadc1);
    int8_t cell_index;

    if(cell_index !=0)
    {
    for(cell_index=cell_number-1;cell_index>=0;cell_index--)
    {

        HAL_Delay(40);

        HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,GPIO_PIN_SET);
        SPI_Transfer24bit(0x00,0x00,Cell_Select_Table[cell_index]|SPI_SAMPLB_ENABLE);
        SPI_Transfer24bit(0x00,0x00,Cell_Select_Table[cell_index]|SPI_SAMPLB_DISABLE);
        HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,GPIO_PIN_RESET);

        HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,GPIO_PIN_SET);
        SPI_Transfer24bit(0x00,0x00,Cell_Select_Table[cell_index]|SPI_SAMPLB_ENABLE);
        SPI_Transfer24bit(0x00,0x00,Cell_Select_Table[cell_index]|SPI_SAMPLB_DISABLE);
        HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,GPIO_PIN_RESET);

        delayUs(5);

        cell_voltage[cell_index]=HAL_ADC_GetValue(&hadc1);

    }
    }
    HAL_ADC_Stop(&hadc1);
}

I have tested delayUs function works fine. But other parts got me dragged down. Any clue or help will be more than favour to me. I just want to learn how to make it work. Datasheet -> https://datasheets.maximintegrated.com/en/ds/MAX14920-MAX14921.pdf

\$\endgroup\$
  • \$\begingroup\$ that should say 16 cell battery .... it is a battery that contains 16 cells \$\endgroup\$ – jsotola Jul 5 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.