cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 STD Periph I2C help

er3481
Senior

Hi,

I want to send 2-bytes from I2C in a single transaction with std peripheral library. For 1-byte i can handle with code below, but how can i send 2 bytes ? Any advise ?

void I2C_Write_Byte(I2C_TypeDef* I2Cx, uint8_t reg_addr , uint8_t reg_data, uint8_t dev_Addr)
{
    switch(i2c_write_seq)
	{
        case 0:
            if(!I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY))
            {
                i2c_write_seq ++ ;
            }
        break;
        case 1:
                I2C_GenerateSTART(I2Cx, ENABLE);
                i2c_write_seq ++ ;
        break;
        case 2:
            if(I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT))
            {
                i2c_write_seq ++ ;
            }
        break;
        case 3:
                I2C_Send7bitAddress(I2Cx, dev_Addr , I2C_Direction_Transmitter);/* Send Device slave Address for write */
                i2c_write_seq ++ ;
        break;
        case 4:
            if(I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
            {
                i2c_write_seq ++ ;
            }
        break;
        case 5:
                I2C_SendData(I2Cx, reg_addr);/* Send the Device internal register address */
                i2c_write_seq ++ ;
        break;
        case 6:
            if(I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
            {
                i2c_write_seq ++ ;
            }
        break;
        case 7:
                I2C_SendData(I2Cx, reg_data);/* Send I2C3 EEPROM data */
                i2c_write_seq ++ ;
        break;
        case 8:
            if(I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
            {
                i2c_write_seq ++ ;
            }
        break;
        case 9:
                I2C_AcknowledgeConfig(I2Cx, DISABLE);
                I2C_GenerateSTOP(I2Cx, ENABLE);/* Send I2C3 STOP Condition */
                I2C_AcknowledgeConfig(I2Cx,ENABLE);/* Enable Acknowledgement to be ready for another reception */
                i2c_write_seq = 0 ;            
        break;
	}
 
}

0 REPLIES 0