1278编程:
1278复位步骤:
NRST = Low 低电平大于100uS, 然后NRST= High 高电平大于5mS 即可完成手动复位。
SPI接口说明:
SPI第一个数据字节为地址域,bit7 为读写控制位, “1” 表示写, “0” 表示读;bit(6-0)对应当前操作的寄存器地址。 在连续读写操作模式时, 寄存器会自动加“1” ,直到NSS脚被拉高;特别注意: FIFO操作时, 寄存器地址不会自动增加, 而是FIFO内的缓存地址。 寄存器的详细说明请参考芯片数据手册的“寄存器说明章节” 。
SPI接口C程序:
在sx1276-Hal.c和spi.c中定义
通讯接口函数使用HAL库中的:HAL_SPI_TransmitReceive()
uint8_t SpiInOut( uint8_t outData )
{
uint8_tretemp;
HAL_SPI_TransmitReceive(&hspi1,&outData,&retemp,1,1000);
returnretemp;
}
SPI通讯接口函数
void SX1276Write( uint8_t addr, uint8_tdata )
{
SX1276WriteBuffer( addr, &data, 1 );
}
void SX1276Read( uint8_t addr, uint8_t*data )
{
SX1276ReadBuffer( addr, data, 1 );
}
void SX1276WriteBuffer( uint8_t addr,uint8_t *buffer, uint8_t size )
{
uint8_t i;
//NSS = 0;
HAL_GPIO_WritePin( RF_NSS_GPIO_Port, RF_NSS_Pin, GPIO_PIN_RESET );
SpiInOut( addr | 0x80 );
for( i = 0; i < size; i++ )
{
SpiInOut( buffer<i> </i>);
}
//NSS = 1;
HAL_GPIO_WritePin( RF_NSS_GPIO_Port, RF_NSS_Pin, GPIO_PIN_SET );
}
void SX1276ReadBuffer( uint8_t addr,uint8_t *buffer, uint8_t size )
{
uint8_t i;
//NSS = 0;
HAL_GPIO_WritePin( RF_NSS_GPIO_Port, RF_NSS_Pin, GPIO_PIN_RESET );
SpiInOut( addr & 0x7F );
for( i = 0; i < size; i++ )
{
buffer = SpiInOut( 0 );
}
//NSS = 1;
HAL_GPIO_WritePin( RF_NSS_GPIO_Port, RF_NSS_Pin, GPIO_PIN_SET );
}
void SX1276WriteFifo( uint8_t *buffer,uint8_t size )
{
SX1276WriteBuffer( 0, buffer, size );
}
void SX1276ReadFifo( uint8_t *buffer,uint8_t size )
{
SX1276ReadBuffer( 0, buffer, size );
}
数字I/O接口函数:
中断函数
数字IO管脚功能配置
外部中断上升沿触发,下拉
1278扩频模块参数修改
在文件sx1276-LoRa.c中,由该结构体初始化模块参数
typedef struct sLoRaSettings
{
uint32_t RFFrequency;
int8_t Power;
uint8_t SignalBw; // LORA [0: 7.8 kHz, 1: 10.4 kHz, 2: 15.6 kHz, 3: 20.8 kHz, 4: 31.2 kHz,
// 5: 41.6 kHz, 6: 62.5 kHz, 7:125 kHz, 8: 250 kHz, 9: 500 kHz, other: Reserved]
uint8_t SpreadingFactor; // LORA [6: 64, 7: 128, 8: 256, 9: 512, 10: 1024, 11: 2048, 12:4096 chips]
uint8_t ErrorCoding; // LORA [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
bool CrcOn; // [0: OFF, 1: ON]
bool ImplicitHeaderOn; // [0: OFF, 1: ON]
bool RxSingleOn; // [0: Continuous, 1 Single]
bool FreqHopOn; // [0: OFF, 1: ON]
uint8_t HopPeriod; // Hops every frequency hopping period symbols
uint32_t TxPacketTimeout;
uint32_t RxPacketTimeout;
uint8_t PayloadLength;
}tLoRaSettings;
例:
tLoRaSettings LoRaSettings =
{
433000000, // RFFrequency
20, // Power
9, // SignalBw [0: 7.8kHz, 1: 10.4kHz, 2: 15.6 kHz, 3: 20.8 kHz, 4: 31.2 kHz,
// 5: 41.6 kHz, 6: 62.5 kHz, 7: 125 kHz, 8: 250 kHz, 9: 500 kHz, other:Reserved]
7, // SpreadingFactor [6: 64, 7:128, 8: 256, 9: 512, 10: 1024, 11: 2048, 12: 4096 chips]
2, // ErrorCoding[1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
true, // CrcOn [0:OFF, 1: ON]
false, // ImplicitHeaderOn [0: OFF, 1: ON]
1, // RxSingleOn[0: Continuous, 1 Single]
0, // FreqHopOn [0:OFF, 1: ON]
4, // HopPeriodHops every frequency hopping period symbols
300, // TxPacketTimeout
300, //RxPacketTimeout
128, //PayloadLength (used for implicit header mode)
}; |