Close

More Testing...

A project log for LoRaWAN Feather

An Adafruit-compatible, LoRaWAN-compatible board.

AndyAndy 12/15/2019 at 16:320 Comments

Time now to take a look at the STC3100 fuel gauge IC.  As a starting point, I'll be using this library on GitHub.  I'm not sure if it is an official ST repository/account, but the driver looks useable.  It just needs an I2C implementation added to it.  I've pulled the 4 required files out and put them into my own repository.  To initially test the code, I'm using the Charger 2 Click from Mikroe in my Clicker 2.  The Clicker 2 uses an STM32F4 but that will allow me to reuse the code on the STM32L0 on the LoRaWAN Feather thanks to CubeMX.  The STM32F4 project is based on FreeRTOS and CubeMX.  Of course, FreeRTOS isn't required as we'll see on the code that runs on the Feather.  Here are the I2C methods I wrote to talk to the chip:

First, STC3100_Write

int STC3100_Write(unsigned char ByteCount, unsigned char RegisterAddr , unsigned char * TxBuffer)
{
	HAL_StatusTypeDef halRet = HAL_OK;
	uint8_t *buf;

	if(ByteCount == 0)
	{
		return(halRet = HAL_ERROR);
	}

	buf = pvPortMalloc((size_t)(ByteCount + 1));

	if(!buf)
	{
		return(halRet = HAL_ERROR);
	}

	buf[0] = RegisterAddr;

	for(int i = 0; i < ByteCount; i++)
	{
		buf[i+1] = TxBuffer[i];
	}

	halRet = HAL_I2C_Master_Transmit(&hi2c3, STC3100_SLAVE_ADDRESS_8BIT, buf, ByteCount+1, HAL_MAX_DELAY);

	if(halRet != HAL_OK)
	{
		return halRet;
	}

	vPortFree(buf);

	return halRet;
} 

Discussions