EZI2C的读写疑问

[复制链接]
2415|0
 楼主| thammer 发表于 2015-1-7 12:33 | 显示全部楼层 |阅读模式
本帖最后由 thammer 于 2015-1-7 17:13 编辑

我的应用场景是一片主MCU来访问cypress一款电容传感器capsense的芯片,capsense作为从机,主机发起一个命令,写EZI2C,从机读取EZI2C对应的buffer[0]作出响应,然后从机也往EZI2C里面的buffer[1]写入一个值作为反馈信息给主MCU。

我看了IDE自带的例子程序:
  1. #include <project.h>
  2. #include <header.h>

  3. /* EZI2C slave buffer for write and read */
  4. uint8 ezI2cBuffer[BUFFER_SIZE] = {PACKET_SOP, STS_CMD_FAIL, PACKET_EOP, PACKET_SOP, STS_CMD_FAIL, PACKET_EOP};


  5. /*******************************************************************************
  6. * Function Name: main
  7. ********************************************************************************
  8. * Summary:
  9. *  The main function performs the following actions:
  10. *   1. Turns off RGB LED.
  11. *   2. Sets up EZI2C slave buffer.
  12. *   3. Starts I2C slave (SCB mode) component.
  13. *   4. Enables global interrupts.
  14. *   5. Waits for command from the I2C master to control the RGB LED.
  15. *
  16. * Parameters:
  17. *  None
  18. *
  19. * Return:
  20. *  None
  21. *
  22. *******************************************************************************/
  23. void main()
  24. {
  25.     uint8 status = STS_CMD_FAIL;

  26.     RGB_LED_OFF;

  27.     /* Setup buffer and start EZI2C slave (SCB mode) */
  28.     EZI2C_EzI2CSetBuffer1(BUFFER_SIZE, READ_ONLY_OFFSET, ezI2cBuffer);
  29.     EZI2C_Start();

  30.     CyGlobalIntEnable;

  31.     for(;;)
  32.     {
  33.         /* Write complete: parse packet */
  34.         if (0u != (EZI2C_EzI2CGetActivity() & EZI2C_EZI2C_STATUS_WRITE1))
  35.         {
  36.             /* Check start and end of packet markers */
  37.             if ((ezI2cBuffer[PACKET_SOP_POS] == PACKET_SOP) &&
  38.                 (ezI2cBuffer[PACKET_EOP_POS] == PACKET_EOP))
  39.             {
  40.                 status = ExecuteCommand(ezI2cBuffer[PACKET_CMD_POS]);
  41.             }

  42.             /* Update buffer with status */
  43.             ezI2cBuffer[PACKET_STS_POS] = status;
  44.             status = STS_CMD_FAIL;
  45.         }

  46.         /* Buffer is always available to be read */
  47.     }
  48. }


  49. /*******************************************************************************
  50. * ExecuteCommand(): executes received command and returns status
  51. *******************************************************************************/
  52. uint8 ExecuteCommand(uint32 cmd)
  53. {
  54.     uint8 status;

  55.     status = STS_CMD_DONE;

  56.     /* Execute received command */
  57.     switch (cmd)
  58.     {
  59.         case CMD_SET_RED:
  60.             RGB_LED_ON_RED;
  61.             break;

  62.         case CMD_SET_GREEN:
  63.             RGB_LED_ON_GREEN;
  64.             break;

  65.         case CMD_SET_BLUE:
  66.             RGB_LED_ON_BLUE;
  67.             break;

  68.         case CMD_SET_OFF:
  69.             RGB_LED_OFF;
  70.             break;

  71.         default:
  72.             status = STS_CMD_FAIL;
  73.         break;
  74.     }

  75.     return(status);
  76. }


  77. /* [] 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就可以了。


您需要登录后才可以回帖 登录 | 注册

本版积分规则

13

主题

34

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部