Omron D6F-PH User Manual page 31

Mems differential pressure sensor
Table of Contents

Advertisement

I2C1_Start();
I2C1_MastrSel(add, 1);
I2C1_AckEn();
rd_fifo[0] = I2C1_rcvdata(); /* Read Data */
I2C1_AckDis();
I2C1_Stop();
rd_fifo[1] = I2C1_rcvdata(); /* Read Data */
uRD_FIFO = ((rd_fifo[0] << 8) | rd_fifo[1]);
return uRD_FIFO;
}
void I2C1_Init(){
I2C_InitTypeDef I2C1_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
I2C
I2C1_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C1_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C1_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C1_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C1_InitStructure.I2C_ClockSpeed = 400000;
GPIO_InitTypeDef GPIO_InitStructure;
InitStructure
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
pins
GPIO_InitStructure.GPIO_Pin =( I2C1_SCL_PIN | I2C1_SDA_PIN );
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
I2C_DeInit(I2C1);
I2C_Init(I2C1, &I2C1_InitStructure); // Initialize with above parameters
I2C_Cmd(I2C1, ENABLE);
}
void I2C1_Start(){
I2C_GenerateSTART(I2C1,ENABLE); // issue start condition
while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT));
}
void I2C1_MastrSel( uint8_t address, uint8_t RW){
uint8_t direct;
uint32_t event;
direct =(RW == 0)?I2C_Direction_Transmitter : I2C_Direction_Receiver;
event
=(RW
I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED;
D6F-PH MEMS Differential pressure Sensor User's Manual (A288)
/* Re-Start condition */
/* Slave 7bit => 8bit for RD */
/* ack enable send after MSB 1 byte read */
/* ack diable send after LSB 1 byte read */
/* Stop condition send */
==
0)?I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED
// start clock of
// make instance of
// start clock of GPIO
30
:

Advertisement

Table of Contents
loading

Table of Contents