开发环境:IAR for STM8
芯片:STM8S105K4
内容:因为之前用STM8S105K4开发过CC1101RF模块用的是io模拟spi。因此开发LoRa也用了io模拟spi结果LoRa初始化没问题,但是一发包/收包就会死。
io模拟spi如下
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104void LORA_delay(unsigned int n) { unsigned int m=0; for(m=0; m<n; m++); for(m=0; m<n; m++); } unsigned char LORA_MISO_IN_FUN(void) { unsigned int i = 10000; while(i--) { if(!LORA_MISO_IN()) return 0; } return 1; } unsigned char LORA_ReadWriteByte(unsigned char value) { unsigned char temp=0x00, count=0x00; LORA_SCLK_LOW();//将时钟线拉低 LORA_delay(1); for(count=0x80; count>0; count>>=1) //数据从高到低写出和读入 { if(value & count) { LORA_MOSI_HIGH(); } else { LORA_MOSI_LOW(); } LORA_delay(1); LORA_SCLK_HIGH();//将时钟线置高,数据写入模块 LORA_delay(1); if(LORA_MISO_IN()) { temp |= count;//从模块读出数据 } LORA_delay(1); LORA_SCLK_LOW();//将时钟线拉低 LORA_delay(1); } return temp; } void SX1276Write( uint8_t addr, uint8_t data ) { addr=addr|0x80; LORA_CSN_LOW(); //片选致能 while(LORA_MISO_IN()); //if(LORA_MISO_IN_FUN()) //return; LORA_ReadWriteByte(addr); //命令写入 LORA_ReadWriteByte(data); //写数据 LORA_CSN_HIGH(); //片选禁能 } void SX1276Read( uint8_t addr, uint8_t *data ) { addr=addr&0x7F; LORA_CSN_LOW(); //片选致能 while(LORA_MISO_IN()); //if(LORA_MISO_IN_FUN()) //return; LORA_ReadWriteByte(addr); //地址 data[0] = LORA_ReadWriteByte(0x00);//读出数据 LORA_CSN_HIGH(); //片选禁能 } void SX1276WriteBuffer( uint8_t addr, uint8_t *buffer, uint8_t size ) { uint8_t count = 0x0; addr=addr|0x80; LORA_CSN_LOW(); //片选致能 while(LORA_MISO_IN()); //if(LORA_MISO_IN_FUN()) //return; LORA_ReadWriteByte(addr); //地址 + 连续写命令 for (count=0; count<size; count++) { LORA_ReadWriteByte(buffer[count]); //写入数据 } LORA_CSN_HIGH(); //片选禁能 } void SX1276ReadBuffer( uint8_t addr, uint8_t *buffer, uint8_t size ) { unsigned char count = 0x0 ; addr=addr&0x7F; LORA_CSN_LOW(); //片选致能 while(LORA_MISO_IN()); //if(LORA_MISO_IN_FUN()) //return; LORA_ReadWriteByte(addr); //地址 for (count = 0; count < size; count++) { buffer[count] = LORA_ReadWriteByte(0x00);//读出数据 } LORA_CSN_HIGH(); //片选禁能 }
总结:
最终还是没找到原因,不过我用硬件spi调试LoRa一切正常。
最后
以上就是幸福小鸭子最近收集整理的关于LoRa之spi调试卡死的全部内容,更多相关LoRa之spi调试卡死内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复