LTC6811-1 Turning ON MOSFETs

Hi

I am trying to operate LTC6811-1 Battery monitoring IC with STM32F3 Microcontroller. I want to turn OFF a particular MOSFET in the cell balancing system in DC2259A  through SPI communication . What is the instruction algorithm /  frame format  for controlling the  Mosfet through spi  ?

Do you have any suggestion or solution for my case so that I can control mosfets for my cell balancing system.

Thank you in advance.

Top Replies

  • 0
    •  Analog Employees 
    on Feb 18, 2020 3:59 PM

    Hi,

    You can go through the LTSketchBook code as a reference. You have to set the DCC bits high to enable the balancing MOSFETS

  • Hello Abhishek,

      The code  is as follow, but MOSFET has no response.  Please let me know if there is something that needs to be changed.


    cmd[0]=0x00;
    cmd[1]=0x01; //Command code
    pec[0]=0x3D

    pec[1]=0x6E

    cfgr[0]= 0xFC ;

    cfgr[1]=0x00;
    cfgr[2]=0x00;
    cfgr[3]=0x00;
    cfgr[4]=0x01; //To turn on MOSFET1
    cfgr[5]=0x00;

    pec[2]=0x04;

    pec[3]=0x88

    ThankYou !

  • 0
    •  Analog Employees 
    on Feb 25, 2020 10:59 AM in reply to Phoenix123

    How are you calculating the data PEC? It looks incorrect to me. There is a function in LTSketchBook which automatically generates the PEC of any given data. As per the function pec[2] = 0xC7 and pec[3] = 0xCE

    After this, can you do a RDCFG to check if DCC[1] is set to 1?

  • Calculated PEC using the same function in LTSketchBook with some changes to use with Keil . There is still  no response to MOSFETs after replacing pec[2] = 0xC7 and pec[3] = 0xCE .

    #include "main.h"
    #include "i2c.h"
    #include "spi.h"
    #include "usb.h"
    #include "gpio.h"
    
        	uint8_t cmd[4];
    	uint8_t cmd1[2];
    	uint8_t cmd2[4];
    	uint8_t cmd3[7];
    	uint8_t CFGR[6];
       	 uint16_t cmd_pec;
    	uint16_t cmd_pec0;
    	uint16_t cmd_pec1;
    	uint16_t cmd_pec2;
    
    void SystemClock_Config(void);
    int main(void)
    {
      HAL_Init();
    
      SystemClock_Config();
      MX_GPIO_Init();
      MX_SPI1_Init();
      
    //CC
    	cmd[0]=0x00;
    	cmd[1]=0x01;
    	
        cmd_pec = pec15_calc(2, cmd);
        cmd[2] = (uint8_t)(cmd_pec >> 8);
        cmd[3] = (uint8_t)(cmd_pec);
    	
    
    //CFGR
    	CFGR[0]=0xFC;
    	CFGR[1]=0x00;
    	CFGR[2]=0x00;
    	CFGR[3]=0x00;
    	CFGR[4]=0x01;
    	CFGR[5]=0x00;
    	
    	cmd_pec1 = pec15_calc(2, CFGR);
    	cmd1[0] =(uint8_t)(cmd_pec1 >> 8);
       	cmd1[1] =(uint8_t)(cmd_pec1);
    	
    //RDCFG
    	cmd2[0]=0x00;
    	cmd2[1]=0x02;
    	
        cmd_pec2 = pec15_calc(2, cmd2);
        cmd2[2] = (uint8_t)(cmd_pec2 >> 8);
        cmd2[3] = (uint8_t)(cmd_pec2);
    
      while (1)
      {
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
    
    		HAL_SPI_Transmit(&hspi1, &cmd[0],1, 1); 
    		HAL_SPI_Transmit(&hspi1, &cmd[1],1, 1);
    		HAL_SPI_Transmit(&hspi1, &cmd[2],1, 1);
    		HAL_SPI_Transmit(&hspi1, &cmd[3],1, 1);
    	
    		HAL_SPI_Transmit(&hspi1, &CFGR[0],1, 1);
    		HAL_SPI_Transmit(&hspi1, &CFGR[1],1, 1);
    		HAL_SPI_Transmit(&hspi1, &CFGR[2],1, 1);
    		HAL_SPI_Transmit(&hspi1, &CFGR[3],1, 1);
    		HAL_SPI_Transmit(&hspi1, &CFGR[4],1, 1);
    		HAL_SPI_Transmit(&hspi1, &CFGR[5],1, 1);
    		
    		HAL_SPI_Transmit(&hspi1, &cmd1[0],1, 1);
    		HAL_SPI_Transmit(&hspi1, &cmd1[1],1, 1);
    
    	
    		HAL_SPI_Transmit(&hspi1, &cmd2[0],1, 1); 
    		HAL_SPI_Transmit(&hspi1, &cmd2[1],1, 1);
    		HAL_SPI_Transmit(&hspi1, &cmd2[2],1, 1);
    		HAL_SPI_Transmit(&hspi1, &cmd2[3],1, 1);
    	
    		HAL_SPI_Receive(&hspi1, &cmd3[0],1, 1);
    
    HAL_SPI_Receive(&hspi1, &cmd3[1],1, 1);
    
    HAL_SPI_Receive(&hspi1, &cmd3[2],1, 1);
    
    HAL_SPI_Receive(&hspi1, &cmd3[3],1, 1);
    
    HAL_SPI_Receive(&hspi1, &cmd3[4],1, 1);
    
    HAL_SPI_Receive(&hspi1, &cmd3[5],1, 1);
    
    HAL_SPI_Receive(&hspi1, &cmd3[6],1, 1);
    
    HAL_SPI_Receive(&hspi1, &cmd3[7],1, 1);
    
    		
    		HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
    		HAL_Delay(10);
    
      }
    }
    
    
    void SystemClock_Config(void)
    {
      RCC_OscInitTypeDef RCC_OscInitStruct = {0};
      RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
      RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
    
      /** Initializes the CPU, AHB and APB busses clocks 
      */
      RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE;
      RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
      RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
      RCC_OscInitStruct.HSIState = RCC_HSI_ON;
      RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
      RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
      RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
      RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
      if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
      {
        Error_Handler();
      }
      /** Initializes the CPU, AHB and APB busses clocks 
      */
      RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                                  |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
      RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
      RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
      RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
      RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
    
      if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
      {
        Error_Handler();
      }
      PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB|RCC_PERIPHCLK_I2C1;
      PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI;
      PeriphClkInit.USBClockSelection = RCC_USBCLKSOURCE_PLL;
      if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
      {
        Error_Handler();
      }
    }
    
    
    
    const uint16_t crc15Table[256]= {0x0,0xc599, 0xceab, 0xb32, 0xd8cf, 0x1d56, 0x1664, 0xd3fd, 0xf407, 0x319e, 0x3aac,  // precomputed CRC15 Table
                                    0xff35, 0x2cc8, 0xe951, 0xe263, 0x27fa, 0xad97, 0x680e, 0x633c, 0xa6a5, 0x7558, 0xb0c1,
                                    0xbbf3, 0x7e6a, 0x5990, 0x9c09, 0x973b, 0x52a2, 0x815f, 0x44c6, 0x4ff4, 0x8a6d, 0x5b2e,
                                    0x9eb7, 0x9585, 0x501c, 0x83e1, 0x4678, 0x4d4a, 0x88d3, 0xaf29, 0x6ab0, 0x6182, 0xa41b,
                                    0x77e6, 0xb27f, 0xb94d, 0x7cd4, 0xf6b9, 0x3320, 0x3812, 0xfd8b, 0x2e76, 0xebef, 0xe0dd,
                                    0x2544, 0x2be, 0xc727, 0xcc15, 0x98c, 0xda71, 0x1fe8, 0x14da, 0xd143, 0xf3c5, 0x365c,
                                    0x3d6e, 0xf8f7,0x2b0a, 0xee93, 0xe5a1, 0x2038, 0x7c2, 0xc25b, 0xc969, 0xcf0, 0xdf0d,
                                    0x1a94, 0x11a6, 0xd43f, 0x5e52, 0x9bcb, 0x90f9, 0x5560, 0x869d, 0x4304, 0x4836, 0x8daf,
                                    0xaa55, 0x6fcc, 0x64fe, 0xa167, 0x729a, 0xb703, 0xbc31, 0x79a8, 0xa8eb, 0x6d72, 0x6640,
                                    0xa3d9, 0x7024, 0xb5bd, 0xbe8f, 0x7b16, 0x5cec, 0x9975, 0x9247, 0x57de, 0x8423, 0x41ba,
                                    0x4a88, 0x8f11, 0x57c, 0xc0e5, 0xcbd7, 0xe4e, 0xddb3, 0x182a, 0x1318, 0xd681, 0xf17b,
                                    0x34e2, 0x3fd0, 0xfa49, 0x29b4, 0xec2d, 0xe71f, 0x2286, 0xa213, 0x678a, 0x6cb8, 0xa921,
                                    0x7adc, 0xbf45, 0xb477, 0x71ee, 0x5614, 0x938d, 0x98bf, 0x5d26, 0x8edb, 0x4b42, 0x4070,
                                    0x85e9, 0xf84, 0xca1d, 0xc12f, 0x4b6, 0xd74b, 0x12d2, 0x19e0, 0xdc79, 0xfb83, 0x3e1a, 0x3528,
                                    0xf0b1, 0x234c, 0xe6d5, 0xede7, 0x287e, 0xf93d, 0x3ca4, 0x3796, 0xf20f, 0x21f2, 0xe46b, 0xef59,
                                    0x2ac0, 0xd3a, 0xc8a3, 0xc391, 0x608, 0xd5f5, 0x106c, 0x1b5e, 0xdec7, 0x54aa, 0x9133, 0x9a01,
                                    0x5f98, 0x8c65, 0x49fc, 0x42ce, 0x8757, 0xa0ad, 0x6534, 0x6e06, 0xab9f, 0x7862, 0xbdfb, 0xb6c9,
                                    0x7350, 0x51d6, 0x944f, 0x9f7d, 0x5ae4, 0x8919, 0x4c80, 0x47b2, 0x822b, 0xa5d1, 0x6048, 0x6b7a,
                                    0xaee3, 0x7d1e, 0xb887, 0xb3b5, 0x762c, 0xfc41, 0x39d8, 0x32ea, 0xf773, 0x248e, 0xe117, 0xea25,
                                    0x2fbc, 0x846, 0xcddf, 0xc6ed, 0x374, 0xd089, 0x1510, 0x1e22, 0xdbbb, 0xaf8, 0xcf61, 0xc453,
                                    0x1ca, 0xd237, 0x17ae, 0x1c9c, 0xd905, 0xfeff, 0x3b66, 0x3054, 0xf5cd, 0x2630, 0xe3a9, 0xe89b,
                                    0x2d02, 0xa76f, 0x62f6, 0x69c4, 0xac5d, 0x7fa0, 0xba39, 0xb10b, 0x7492, 0x5368, 0x96f1, 0x9dc3,
                                    0x585a, 0x8ba7, 0x4e3e, 0x450c, 0x8095
                                   };
    //Calculates  and returns the CRC15 
    uint16_t pec15_calc(uint8_t len, //Number of bytes that will be used to calculate a PEC
                        uint8_t *data //Array of data that will be used to calculate  a PEC
                       )
    {
    	uint16_t remainder,addr;
    	remainder = 16;//initialize the PEC
    	
    	for (uint8_t i = 0; i<len; i++) // loops for each byte in data array
    	{
    		addr = ((remainder>>7)^data[i])&0xff;//calculate PEC table address
    		
    			remainder = (remainder<<8)^crc15Table[addr];
    	
    	}
    	
    	return(remainder*2);//The CRC15 has a 0 in the LSB so the remainder must be multiplied by 2
    }
    
    void Error_Handler(void)
    {
      /* USER CODE BEGIN Error_Handler_Debug */
      /* User can add his own implementation to report the HAL error return state */
    
      /* USER CODE END Error_Handler_Debug */
    }
    
    #ifdef  USE_FULL_ASSERT
    /**
      * @brief  Reports the name of the source file and the source line number
      *         where the assert_param error has occurred.
      * @param  file: pointer to the source file name
      * @param  line: assert_param error line source number
      * @retval None
      */
    void assert_failed(char *file, uint32_t line)
    { 
      /* USER CODE BEGIN 6 */
      /* User can add his own implementation to report the file name and line number,
         tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
      /* USER CODE END 6 */
    }
    #endif /* USE_FULL_ASSERT */
    

    am attaching my entire prgrm with this. Can you please help me to sort out the problem  ?