[其他] 基于MindSDK测试MM32F5270开发板IIC

[复制链接]
 楼主| 欢乐家园 发表于 2022-12-24 14:24 | 显示全部楼层 |阅读模式
本篇文章作者:7_c9dtBq
MM32F5270 是基于安谋科技的 Armv-8 架构的“星辰”STAR-MC1 处理器开发的 32 位微控制器产品.本篇文章通过调用MindSDK例程查看内部集成电路接口IIC。

1、环境配置

原本我的keil版本不能兼容MM32F5277E9P芯片包,拿到开发板当天激动的直接添加,结果就是添加芯片包成功,keil的options->target里面也能识别出MindMotion MM32F5277E9P,但是编译却会报错,经过查阅官方资料以及群友的提醒,将keil升级到5.37(必须为5.37及以上,将编译器换成version6)。
9621263a69b1e3a0ef.png

 楼主| 欢乐家园 发表于 2022-12-24 14:36 | 显示全部楼层
之后再添加芯片包,编译hello world demo
8128263a69df10eb80.png
 楼主| 欢乐家园 发表于 2022-12-24 14:40 | 显示全部楼层
可以看到 0错误 0警告
将套件中附赠的PWLINK2的烧录器与开发板接上,keil options debug中按如下配置
9972863a69e005024f.png
 楼主| 欢乐家园 发表于 2022-12-24 14:42 | 显示全部楼层
引脚口在带灵动微MM32F5的Plus-F5270开发板怎么玩? - 极术社区 - 连接开发者与智能计算生态 (aijishu.com)已有说明,接上即可。
1148063a69f4ca1307.png
 楼主| 欢乐家园 发表于 2022-12-24 14:44 | 显示全部楼层
 楼主| 欢乐家园 发表于 2022-12-24 14:47 | 显示全部楼层
烧录程序
6275363a69fededbec.png
 楼主| 欢乐家园 发表于 2022-12-24 14:48 | 显示全部楼层
打开串口程序,配置波特率为9600,8位数据位,1位停止位,无校验位,可以看到成功打印hello,world
6423363a6a0d3ec73a.png
 楼主| 欢乐家园 发表于 2022-12-24 14:53 | 显示全部楼层
测试硬件IIC

环境配置完成,接下来烧写MindSDK自带的IIC例程
780363a6a1fb5a6be.png
 楼主| 欢乐家园 发表于 2022-12-24 14:56 | 显示全部楼层
  1. static I2C_MasterXfer_Type app_i2c_xfer;
  2. volatile static bool app_i2c_xfer_done; /* Xfer done flag. */
  3. static uint8_t app_i2c_rx_buf[APP_I2C_BUF_LEN]; /* I2C rx buffer. */
  4. static uint8_t app_i2c_tx_buf[APP_I2C_BUF_LEN]; /* I2C tx buffer. */

  5. /*
  6. * Declerations.
  7. */
  8. void app_i2c_init(void);
  9. void app_i2c_detect(void);
  10. void app_i2c_rx_abort_callback(void *param);
  11. void app_i2c_rx_done_callback(void *param);
  12. void app_swdelay(uint32_t ms);

  13. /*
  14. * Functions.
  15. */
  16. int main(void)
  17. {
  18. BOARD_Init();
  19. printf("i2c_master_detect example.\r\n");

  20. /* Initialize I2C. */
  21. app_i2c_init();

  22. while (1)
  23. {
  24. printf("press any key to detect I2C.\r\n");
  25. getchar();
  26. app_i2c_detect(); /* Detect operation. */
  27. }
  28. }

  29. /* Detect the operation of write and read. */
  30. void app_i2c_detect()
  31. {
  32. for (uint16_t i = 0x00u; i <= 0xFEu; i += 2u) /* 7bit address is (device address >> 1) ,so judge next address need add 2 in address now. */
  33. {
  34. printf("target: 0x%02X, ", i);

  35. app_i2c_xfer.TargetAddr = i >> 1u; /* Setup target deveice address. */
  36. app_i2c_xfer.Direction = I2C_Direction_Rx; /* Setup the xfer direction. */
  37. app_i2c_xfer.TxBuf = app_i2c_tx_buf; /* Setup xfer buffer. */
  38. app_i2c_xfer.RxBuf = app_i2c_rx_buf; /* Setup rx buffer. */
  39. app_i2c_xfer.TxLen = APP_I2C_TX_LEN; /* Setup xfer buffer data length. */
  40. app_i2c_xfer.RxLen = APP_I2C_RX_LEN; /* Setup xfer buffer data length. */
  41. app_i2c_xfer.AbortCallback = app_i2c_rx_abort_callback; /* Receive abort callback. */
  42. app_i2c_xfer.DoneCallback = app_i2c_rx_done_callback; /* Receive done callback. */
  43. app_i2c_xfer_done = false; /* Setup xfer done flag to xfer not done. */

  44. /* The target device address needs to be configured before enable. */
  45. I2C_Enable(BOARD_I2C_PORT, false);
  46. I2C_SetTargetAddr(BOARD_I2C_PORT, app_i2c_xfer.TargetAddr); /* Set target device address. */
  47. I2C_Enable(BOARD_I2C_PORT, true);

  48. I2C_MasterXfer(BOARD_I2C_PORT, &app_i2c_xfer);

  49. while (false == app_i2c_xfer_done) /* Waiting for xfer done. */
  50. {
  51. }
  52. app_swdelay(10u);
  53. }
  54. }

  55. /* Initialize I2C. */
  56. void app_i2c_init(void)
  57. {
  58. RCC_EnableAPB1Periphs(RCC_APB1_PERIPH_I2C1, true);/* Enable I2C1 clock of APB1 peripheral. */

  59. I2C_Master_Init_Type i2c_initmaster;

  60. /* Configure I2C initialization. */
  61. i2c_initmaster.ClockFreqHz = BOARD_I2C_FREQ;
  62. i2c_initmaster.BaudRate = I2C_BaudRate_100K;

  63. /* Initialize I2C master. */
  64. I2C_InitMaster(BOARD_I2C_PORT, &i2c_initmaster);

  65. /* Enable I2C. */
  66. I2C_Enable(BOARD_I2C_PORT, true);

  67. /* Enable NVIC. */
  68. NVIC_EnableIRQ(BOARD_I2C_IRQn);
  69. }

  70. /* I2C interrupt handler. */
  71. void BOARD_I2C_IRQHandler(void)
  72. {
  73. uint32_t flag = I2C_GetInterruptStatus(BOARD_I2C_PORT); /* Get current interrupt status. */
  74. I2C_ClearInterruptStatus(BOARD_I2C_PORT, flag); /* Clear all software clear the interrupt. */
  75. I2C_MasterXferHandler(BOARD_I2C_PORT, &app_i2c_xfer, flag); /* I2C master xfer interrupt handler. */
  76. }

  77. /* When I2C received done, use app_i2c_rx_done_callback. */
  78. void app_i2c_rx_done_callback(void *param)
  79. {
  80. printf("device exists.\r\n");
  81. app_i2c_xfer_done = true;
  82. }

  83. /* When I2C received abort, use app_i2c_rx_abort_callback. */
  84. void app_i2c_rx_abort_callback(void *param)
  85. {
  86. printf("device not exists.\r\n");
  87. app_i2c_xfer_done = true;
  88. }

  89. /* Software delay millisecond. */
  90. void app_swdelay(uint32_t ms)
  91. {
  92. for (uint32_t i = 0u; i < ms; i++)
  93. {
  94. for (uint32_t j = 0u; j < (CLOCK_SYS_FREQ / 1000u); j++)
  95. {
  96. __NOP();
  97. }
  98. }
  99. }
 楼主| 欢乐家园 发表于 2022-12-24 14:59 | 显示全部楼层
烧写成功,打开串口

4745663a6a36c0db64.png
 楼主| 欢乐家园 发表于 2022-12-24 15:01 | 显示全部楼层
按照源码的逻辑,输入任意值即可检测,这里我输入1
7138663a6a3b0ccc5a.png
可以看到检测到0xA0设备地址了
 楼主| 欢乐家园 发表于 2022-12-24 15:01 | 显示全部楼层
总结
MindSDK集成了大部分外设库文件,快速上手开发神器,最近时间过于仓促,拿到手后爱不释手(可怜学生党),也没有空余的时间去体验开发板的其他功能,好在有强大的MindSDK的强大助力,等这段时间实习的事情忙完后,再来把MM32F5270系统开发一遍。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

113

主题

1030

帖子

1

粉丝
快速回复 返回顶部 返回列表