2017-11-20 11:16 AM
dear ST Community,
i am trying to talk to a smart battery through SMBus as bellow:
to initialize: an I2C of the STM32F407 as SMBus.
to transmit battery address ( slave )
to acknowledge from it
but the command doesn't be send to the battery!
does any body have experience in?
thanks in advance.
the code is here:
hi2c1.Instance->CR1 |= I2C_CR1_START;
if (I2C_WaitOnFlagUntilTimeout(&hi2c1,I2C_FLAG_SB,1,1,0)== 1) {}; // wait on generation // read sr1 sr1or2=hi2c1.Instance->SR1; for ( i1=1;i1<20;i1++) { __NOP;} // wait for read complete // address hi2c1.Instance->DR=0x16; // battery address : 0x16 + 0 ( write )
// ack 1
//EV6 if ( I2C_WaitOnMasterAddressFlagUntilTimeout(&hi2c1,I2C_FLAG_ADDR,1,0) == 1 ) {}// read sr1 and sr2 sr1or2=hi2c1.Instance->SR1; sr1or2=hi2c1.Instance->SR2; if (I2C_WaitOnFlagUntilTimeout(&hi2c1,I2C_FLAG_ADDR,0,1,1)== 1) {}; // // wait for clear addr //EV8_1 if (I2C_WaitOnTXEFlagUntilTimeout(&hi2c1,25,0)== 1) {} // wait for TxE be set for ( i1=1;i1<10;i1++) { __NOP;} // wait for read complete
// command ( data 1 )
hi2c1.Instance->DR=0x08; // command 0x8 : temperature
...
#smbus #smart-battery #read-word-protocol #stm32f4