后记:
之前,我把SPI的片选在Cubemx中配置成了SPI_NSS。
现在我给它改为了GPIO_OUTPUT. 同时参考了别人的类似的一个操作无线模块(采用SPI设备驱动)的例子程序(清楚了RTT的系统API的调用流程)。
年初第一天上班,有空回过头来看这个问题,就成功解决了。
------Sx1278.h-----------------------------------------------------------------------------------------------------
#ifndef __SX1278_H__
#define __SX1278_H__
#include "drv_gpio.h"
struct spi_sx1278_device
{
struct rt_device sx1278_device;
struct rt_spi_device * rt_spi_device;
struct rt_mutex lock;
void * user_data;
};
typedef struct spi_sx1278_device * rt_spi_sx1278_device_t;
// 引脚定义
#define Sx1278_IRQ_PIN GET_PIN(C, 8)
#define Sx1278_nCS_PIN GET_PIN(B, 12)
#define Sx1278_RST_PIN GET_PIN(C, 9)
// 引脚状态
#define ST_SX1278_IRQ() rt_pin_read(Sx1278_IRQ_PIN)
// 引脚输出
#define SX1278_SPI_NCS_H() rt_pin_write(Sx1278_nCS_PIN, PIN_HIGH);
#define SX1278_SPI_NCS_L() rt_pin_write(Sx1278_nCS_PIN, PIN_LOW);
#define SX1278_SPI_RST_H() rt_pin_write(Sx1278_RST_PIN, PIN_HIGH);
#define SX1278_SPI_RST_L() rt_pin_write(Sx1278_RST_PIN, PIN_LOW);
typedef rt_uint8_t u8;
typedef rt_uint16_t u16;
typedef rt_uint32_t u32;
void test(void);
#endif
------Sx1