本帖最后由 thammer 于 2015-1-7 17:13 编辑
我的应用场景是一片主MCU来访问cypress一款电容传感器capsense的芯片,capsense作为从机,主机发起一个命令,写EZI2C,从机读取EZI2C对应的buffer[0]作出响应,然后从机也往EZI2C里面的buffer[1]写入一个值作为反馈信息给主MCU。
我看了IDE自带的例子程序:
- #include <project.h>
- #include <header.h>
- /* EZI2C slave buffer for write and read */
- uint8 ezI2cBuffer[BUFFER_SIZE] = {PACKET_SOP, STS_CMD_FAIL, PACKET_EOP, PACKET_SOP, STS_CMD_FAIL, PACKET_EOP};
- /*******************************************************************************
- * Function Name: main
- ********************************************************************************
- * Summary:
- * The main function performs the following actions:
- * 1. Turns off RGB LED.
- * 2. Sets up EZI2C slave buffer.
- * 3. Starts I2C slave (SCB mode) component.
- * 4. Enables global interrupts.
- * 5. Waits for command from the I2C master to control the RGB LED.
- *
- * Parameters:
- * None
- *
- * Return:
- * None
- *
- *******************************************************************************/
- void main()
- {
- uint8 status = STS_CMD_FAIL;
- RGB_LED_OFF;
- /* Setup buffer and start EZI2C slave (SCB mode) */
- EZI2C_EzI2CSetBuffer1(BUFFER_SIZE, READ_ONLY_OFFSET, ezI2cBuffer);
- EZI2C_Start();
- CyGlobalIntEnable;
- for(;;)
- {
- /* Write complete: parse packet */
- if (0u != (EZI2C_EzI2CGetActivity() & EZI2C_EZI2C_STATUS_WRITE1))
- {
- /* Check start and end of packet markers */
- if ((ezI2cBuffer[PACKET_SOP_POS] == PACKET_SOP) &&
- (ezI2cBuffer[PACKET_EOP_POS] == PACKET_EOP))
- {
- status = ExecuteCommand(ezI2cBuffer[PACKET_CMD_POS]);
- }
- /* Update buffer with status */
- ezI2cBuffer[PACKET_STS_POS] = status;
- status = STS_CMD_FAIL;
- }
- /* Buffer is always available to be read */
- }
- }
- /*******************************************************************************
- * ExecuteCommand(): executes received command and returns status
- *******************************************************************************/
- uint8 ExecuteCommand(uint32 cmd)
- {
- uint8 status;
- status = STS_CMD_DONE;
- /* Execute received command */
- switch (cmd)
- {
- case CMD_SET_RED:
- RGB_LED_ON_RED;
- break;
- case CMD_SET_GREEN:
- RGB_LED_ON_GREEN;
- break;
- case CMD_SET_BLUE:
- RGB_LED_ON_BLUE;
- break;
- case CMD_SET_OFF:
- RGB_LED_OFF;
- break;
- default:
- status = STS_CMD_FAIL;
- break;
- }
- return(status);
- }
- /* [] END OF FILE */
我的疑问是: 当运行代码
EZI2C_EzI2CSetBuffer1(BUFFER_SIZE, READ_ONLY_OFFSET, ezI2cBuffer);
EZI2C_Start();
后,如果需要更新i2c buffer里面的值,只需要直接对变量数组ezI2cBuffer进行赋值操作就可以了吗?
问题我已经搞清楚了,
EZI2C_EzI2CSetBuffer1(BUFFER_SIZE, READ_ONLY_OFFSET, ezI2cBuffer);
EZI2C_Start();
后,直接操作buffer就可以了。
|