完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
经过很多次调试将spi调试成功了。
fasong_data发送函数传值 jieshou_buffer接受值 也可以自主定义数据流。 spi.c *********************************************************** #include "hal.h" #include "system_mt7687.h" #include "top.h" #include "spi.h" #include "inttypes.h" #include "CMSIS.h" #include "led.h" uint32_t fasong_length=1; uint8_t jieshou_buffer={0x00}; uint32_t jieshou_length=2; uint8_t fasong_data={0x00}; void spi_send_and_receive() { fasong_length=1; jieshou_length=2; uint32_t clock_frequency = 1000000; //频率//SPI主时钟频率设置,范围从30000HZ到60000000HZ。 hal_spi_master_config_t spi_config; log_hal_info("---spim_example begin---rn"); hal_gpio_status_t ret; //************ ret = hal_gpio_init(HAL_GPIO_29); if (HAL_GPIO_STATUS_OK != ret) { log_hal_error("hal_gpio_init 29 failedrn"); hal_gpio_deinit(HAL_GPIO_29); return; } ret = hal_gpio_init(HAL_GPIO_30); if (HAL_GPIO_STATUS_OK != ret) { log_hal_error("hal_gpio_init 30 failedrn"); hal_gpio_deinit(HAL_GPIO_30); return; } ret = hal_gpio_init(HAL_GPIO_31); if (HAL_GPIO_STATUS_OK != ret) { log_hal_error("hal_gpio_init 31 failedrn"); hal_gpio_deinit(HAL_GPIO_31); return; } ret = hal_gpio_init(HAL_GPIO_32); if (HAL_GPIO_STATUS_OK != ret) { log_hal_error("hal_gpio_init 32 failedrn"); hal_gpio_deinit(HAL_GPIO_32); return; } hal_gpio_init(HAL_GPIO_28); hal_pinmux_set_function(HAL_GPIO_29, HAL_GPIO_29_SPI_MOSI_M_CM4); hal_pinmux_set_function(HAL_GPIO_30, HAL_GPIO_30_SPI_MISO_M_CM4); hal_pinmux_set_function(HAL_GPIO_31, HAL_GPIO_31_SPI_SCK_M_CM4); hal_pinmux_set_function(HAL_GPIO_32, HAL_GPIO_32_SPI_CS_0_S_CM4); //spi初始化参数 spi_config.bit_order = HAL_SPI_MASTER_MSB_FIRST; spi_config.slave_port = HAL_SPI_MASTER_SLAVE_0; spi_config.clock_frequency = clock_frequency; spi_config.phase = HAL_SPI_MASTER_CLOCK_PHASE0; spi_config.polarity = HAL_SPI_MASTER_CLOCK_POLARITY0; //缓存区属性赋值 hal_spi_master_send_and_receive_config_t spi_send_and_receive_config; spi_send_and_receive_config.receive_buffer = &jieshou_buffer; spi_send_and_receive_config.send_data = &fasong_data; spi_send_and_receive_config.send_length = fasong_length; spi_send_and_receive_config.receive_length = jieshou_length; if (HAL_SPI_MASTER_STATUS_OK != hal_spi_master_init(HAL_SPI_MASTER_0, &spi_config)) { log_hal_info("hal_spi_master_init failn"); return; } //此功能在FIFO模式下同时发送和接收数据。 //此功能在传输完成前不会返回。 //用户应该判断在发送命令期间接收的数据是否有效,并且此信息可以从SPI器件的数据手册获得。 ret = hal_spi_master_send_and_receive_polling(HAL_SPI_MASTER_0, &spi_send_and_receive_config);//轮询模式同时发送和接收数据 if (HAL_SPI_MASTER_STATUS_ERROR== ret) { log_hal_info("spi master send and receive means the byte_order parameter is not configured rightly for the FIFO mode;n");//表示byte_order参数未正确配置为FIFO模式; } else if (HAL_SPI_MASTER_STATUS_ERROR_BUSY== ret) { log_hal_info("spi master send and receive means this port of SPI master is busy and not available for usen");//表示SPI主机的此端口正忙,不可使用; } else if (HAL_SPI_MASTER_STATUS_ERROR_PORT== ret) { log_hal_info("spi master send and receive means master_port parameter is an invalid port numbern");//表示master_port参数是无效的端口号;,不可使用; } else if (HAL_SPI_MASTER_STATUS_INVALID_PARAMETER== ret) { log_hal_info("spi master send and receive means an invalid parameter in spi_send_and_receive_config is givenn");//表示spi_send_and_receive_config中的无效参数; } else{ log_hal_info("spi master send and receive means this function return successfullyn");//表示此函数成功返回。 } ret=hal_spi_master_deinit(HAL_SPI_MASTER_0); if (HAL_SPI_MASTER_STATUS_ERROR_PORT==ret ) { log_hal_info("spi master deinit means master_port parameter is an invalid port numbern");//表示master_port参数是无效的端口号; } else{ log_hal_info("spi master deinit means this function return successfully. n");//表示此函数成功返回。 return; } hal_gpio_deinit(HAL_GPIO_29); hal_gpio_deinit(HAL_GPIO_30); hal_gpio_deinit(HAL_GPIO_31); hal_gpio_deinit(HAL_GPIO_32); } *************************************** spi.h ************************************************** #ifndef _SPI_H_ #define _SPI_H_ #include "hal.h" #include "system_mt7687.h" #include "top.h" #include "spi.h" #include "inttypes.h" #include "CMSIS.h" extern uint32_t fasong_length; extern uint8_t jieshou_buffer; extern uint32_t jieshou_length; extern uint8_t fasong_data; #ifdef __cplusplus extern "C" { #endif void spi_send_and_receive(); #ifdef __cplusplus } #endif #endif /* __SPI433_H_ */
|
|
相关推荐
2 个讨论
|
|
只有小组成员才能发言,加入小组>>
891 浏览 0 评论
【KV260视觉入门套件试用体验】四、KV260 视觉入门套件和固件更新
1463 浏览 0 评论
【KV260视觉入门套件试用体验】Vitis AI Library体验之OCR识别
1113 浏览 0 评论
【KV260视觉入门套件试用体验】Vitis AI 通过迁移学习训练自定义模型
1469 浏览 0 评论
【KV260视觉入门套件试用体验】KV260系列之Petalinux镜像+Resnet 50探索
1133 浏览 0 评论
【AMD KV260视觉入门开发套件试用】4、简单几步体验ubuntu 20.04.3 LTS运行人员检测应用
1612浏览 1评论
888浏览 1评论
【KV260视觉入门套件试用体验】老刘记事儿KV260初体验之Micro-SD选型提速研究(三)
828浏览 1评论
【KV260视觉入门套件试用体验】KV260部署yolov3实现车辆和行人检测
2426浏览 1评论
【KV260视觉入门套件试用体验】基于KV260的人脸识别的实现与展示
818浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-14 17:34 , Processed in 0.639198 second(s), Total 78, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号