I2C reading and writing function

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
rbtics
Level 1
Level 1
10 sign-ins 5 replies posted 5 sign-ins

I am trying to write a program for the BNO055 device by BOSHC. I have the driver as a master since I need to connect with the I2C but I am confused about how to use the I2C API's. I know that I have to use uint32 SCB_I2CMasterReadBuf(uint32 slaveAddress, uint8 * rdData, uint32 cnt, uint32 mode) for me to be able to read from the registers, but I am confused about what to pass into the function. Any help would be appreciated!

0 Likes
1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

for uint32 SCB_I2CMasterReadBuf(uint32 slaveAddress, uint8 * rdData, uint32 cnt, uint32 mode)

In the I2C_I2C.h

/*******************************************************************************
* Function Name: I2C_I2CMasterReadBuf
****************************************************************************//**
*
* Automatically reads an entire buffer of data from a slave device.
* Once the data transfer is initiated by this function, further data transfer
* is handled by the included ISR.
* Enables the I2C interrupt and clears I2C_I2C_MSTAT_RD_CMPLT
* status.
*
* \param slaveAddr: 7-bit slave address.
* \param xferData: Pointer to buffer of data to be sent.
* \param cnt: Size of buffer to send.
* \param mode: Transfer mode defines:
* (1) Whether a start or restart condition is generated at the beginning
* of the transfer, and
* (2) Whether the transfer is completed or halted before the stop
* condition is generated on the bus.Transfer mode, mode constants may
* be ORed together. See I2C_I2CMasterWriteBuf()
* function for constants.
*
* \return
* Error status.See I2C_I2CMasterWriteBuf()
* function for constants.
*
* \globalvars
* I2C_mstrStatus - used to store current status of I2C Master.
* I2C_state - used to store current state of software FSM.
* I2C_mstrControl - used to control master end of transaction with
* or without the Stop generation.
* I2C_mstrRdBufPtr - used to store pointer to master read buffer.
* I2C_mstrRdBufIndex - used to current index within master read
* buffer.
* I2C_mstrRdBufSize - used to store master read buffer size.
*
*******************************************************************************/
uint32 I2C_I2CMasterReadBuf(uint32 slaveAddress, uint8 * rdData, uint32 cnt, uint32 mode)

Meantime, the followings are sample programs I wrote to show how to use simple functions

PSoC 4
https://community.cypress.com/t5/Code-Examples/MCU-Tester-a-Swiss-Army-Knife-for-PSoC-CY8CKIT-044-ve...

PSoC 5LP
https://community.cypress.com/t5/Code-Examples/MCU-Tester-a-Swiss-Army-Knife-for-PSoC-CY8CKIT-059-ve...

PSoC 6
https://community.cypress.com/t5/Code-Examples/MCU-Tester-a-Swiss-Army-Knife-for-PSoC-CY8CKIT-062-BL...

moto

View solution in original post

1 Reply
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

for uint32 SCB_I2CMasterReadBuf(uint32 slaveAddress, uint8 * rdData, uint32 cnt, uint32 mode)

In the I2C_I2C.h

/*******************************************************************************
* Function Name: I2C_I2CMasterReadBuf
****************************************************************************//**
*
* Automatically reads an entire buffer of data from a slave device.
* Once the data transfer is initiated by this function, further data transfer
* is handled by the included ISR.
* Enables the I2C interrupt and clears I2C_I2C_MSTAT_RD_CMPLT
* status.
*
* \param slaveAddr: 7-bit slave address.
* \param xferData: Pointer to buffer of data to be sent.
* \param cnt: Size of buffer to send.
* \param mode: Transfer mode defines:
* (1) Whether a start or restart condition is generated at the beginning
* of the transfer, and
* (2) Whether the transfer is completed or halted before the stop
* condition is generated on the bus.Transfer mode, mode constants may
* be ORed together. See I2C_I2CMasterWriteBuf()
* function for constants.
*
* \return
* Error status.See I2C_I2CMasterWriteBuf()
* function for constants.
*
* \globalvars
* I2C_mstrStatus - used to store current status of I2C Master.
* I2C_state - used to store current state of software FSM.
* I2C_mstrControl - used to control master end of transaction with
* or without the Stop generation.
* I2C_mstrRdBufPtr - used to store pointer to master read buffer.
* I2C_mstrRdBufIndex - used to current index within master read
* buffer.
* I2C_mstrRdBufSize - used to store master read buffer size.
*
*******************************************************************************/
uint32 I2C_I2CMasterReadBuf(uint32 slaveAddress, uint8 * rdData, uint32 cnt, uint32 mode)

Meantime, the followings are sample programs I wrote to show how to use simple functions

PSoC 4
https://community.cypress.com/t5/Code-Examples/MCU-Tester-a-Swiss-Army-Knife-for-PSoC-CY8CKIT-044-ve...

PSoC 5LP
https://community.cypress.com/t5/Code-Examples/MCU-Tester-a-Swiss-Army-Knife-for-PSoC-CY8CKIT-059-ve...

PSoC 6
https://community.cypress.com/t5/Code-Examples/MCU-Tester-a-Swiss-Army-Knife-for-PSoC-CY8CKIT-062-BL...

moto