LT8900无线模块SPI的读写
最近在用LT8900这个2.4G模块,刚刚写好一个SPI读写程序,发上来给用过的高手看一下对不,等完全调通了再总结一下心得传上来。;;------------------------------------SPI读写程序
SPI_Write:
bclr SPI_SS ;使能SPI信号 SPI_SS=0有效
call DELAY_1MS ;延时1MS
;---------------
movar REG ;寄存器地址
movra SEND_DATA ;REG最高位为0,SPI_Write,7=0表示写
call SPI_Wbyte
;---------------
movar H_8BIT ;高8bit
movra SEND_DATA
call SPI_Wbyte
;---------------
movar L_8BIT ;低8b8t
movra SEND_DATA
call SPI_Wbyte
bset SPI_SS ;SPI_SS=1
return
;------------------------------------SPI读程序
SPI_Read:
bclr SPI_SS ;使能SPI信号 SPI_SS=0有效
call DELAY_1MS ;延时1MS
bset reg,7 ;强制reg最高位为1,Spi_Read,7=1表示读
movar REG
movra SEND_DATA ;读的地址
call SPI_Wbyte
;---------------
call SPI_Rbyte
movar READ_DATA
movra SPI_R1 ;读出数据1
;----------------
call SPI_Rbyte
movar READ_DATA
movra SPI_R2 ;读出数据2
bset SPI_SS ;SPI_SS=1
return
;-------------------------------------SPI写一个8位字节-SPI0模式-时钟线默认低,第一个脉冲写
SPI_Wbyte:
movai 8
movra SPI_COUNT
SPI_Wbyte_1:
rlr SEND_DATA ;数据左移,先发最高位
jbclr C ;左移的数据都可以根据这个标志位判断是0还是1
goto SPI_Wbyte_2
bclr SPI_MOSI ;移出byte"0"
goto SPI_Wbyte_3
SPI_Wbyte_2:
BSET SPI_MOSI ;移出byte"1"
SPI_Wbyte_3:
bset SPI_CLK ;时钟线置高-上升沿 CLK=1
call SPI_Delay
bclr SPI_CLK ;时钟线置低-下降沿采样完成 CLK=0
call SPI_Delay
SPI_Wbyte_4:
djzr SPI_COUNT ;循环8次
goto SPI_Wbyte_1
return
;--------------------------------------SPI读一个8位字节
SPI_Rbyte:
movai 8
movra SPI_COUNT
SPI_Rbyte_1:
bset SPI_CLK ;时钟线置高-上升沿 CKL=1
call SPI_Delay
bclr SPI_CLK ;时钟线置低-下降沿MISO数据已经传输过来 CKL=0
jbset SPI_MISO ;判断MISO是"0"还是"1"循环8次存到READ_DATA
goto SPI_Rbyte_2
bset C ;C位可以左移移进READ_DATA
goto SPI_Rbyte_3
SPI_Rbyte_2:
bclr C
SPI_Rbyte_3:
rlr READ_DATA
djzr SPI_COUNT ;循环8次
goto SPI_Rbyte_1
return
;-------------------------------------SPI延时程序
SPI_Delay:
nop
nop
nop
nop
nop
nop
nop
nop
return 初始化程序在这个,汇编写的,比较繁琐,参考别人配置的:
bclr SPI_RST ;SPI_RST=0关芯片寄存器值失去
call DELAY_1MS
bset SPI_RST ;SPI_RST=1开芯片
call DELAY_8MS
call SPI_Init
movai 0 ;寄存器0-6FE0
movra REG
movai 0x6f
movra H_8BIT
movai 0xe0
movra L_8BIT
call SPI_Write;--
movai 1 ;寄存器1-5681
movra REG
movai 0x56
movra H_8BIT
movai 0x81
movra L_8BIT
call SPI_Write;--
movai 2 ;寄存器2-6617
movra REG
movai 0x66
movra H_8BIT
movai 0x17
movra L_8BIT
call SPI_Write
movai 4 ;寄存器4-9CC9
movra REG
movai 0x9C
movra H_8BIT
movai 0xC9
movra L_8BIT
call SPI_Write
movai 5 ;寄存器5-6637
movra REG
movai 0x66
movra H_8BIT
movai 0x37
movra L_8BIT
call SPI_Write
movai 7 ;寄存器7-0030
movra REG
movai 0x00
movra H_8BIT
movai 0x30
movra L_8BIT
call SPI_Write
movai 8 ;寄存器8-6C90
movra REG
movai 0x6C
movra H_8BIT
movai 0x90
movra L_8BIT
call SPI_Write
movai 9 ;寄存器9-1840
movra REG
movai 0x18
movra H_8BIT
movai 0x40
movra L_8BIT
call SPI_Write
movai 10 ;寄存器10-7FFD
movra REG
movai 0x7F
movra H_8BIT
movai 0xFD
movra L_8BIT
call SPI_Write
movai 11 ;寄存器11-0008
movra REG
movai 0x00
movra H_8BIT
movai 0x08
movra L_8BIT
call SPI_Write
movai 12 ;寄存器12-0000
movra REG
movai 0x00
movra H_8BIT
movai 0x00
movra L_8BIT
call SPI_Write
movai 13 ;寄存器13-48BD
movra REG
movai 0x48
movra H_8BIT
movai 0xBD
movra L_8BIT
call SPI_Write
movai 22 ;寄存器22-00FF
movra REG
movai 0x00
movra H_8BIT
movai 0xFF
movra L_8BIT
call SPI_Write
movai 23 ;寄存器23-8005
movra REG
movai 0x80
movra H_8BIT
movai 0x05
movra L_8BIT
call SPI_Write
movai 24 ;寄存器24-0067
movra REG
movai 0x00
movra H_8BIT
movai 0x67
movra L_8BIT
call SPI_Write
movai 25 ;寄存器25-1659
movra REG
movai 0x16
movra H_8BIT
movai 0x59
movra L_8BIT
call SPI_Write
movai 26 ;寄存器26-19E0
movra REG
movai 0x19
movra H_8BIT
movai 0xE0
movra L_8BIT
call SPI_Write
movai 27 ;寄存器27-1300
movra REG
movai 0x13
movra H_8BIT
movai 0x00
movra L_8BIT
call SPI_Write
movai 28 ;寄存器28-1800
movra REG
movai 0x18
movra H_8BIT
movai 0x00
movra L_8BIT
call SPI_Write
movai 32 ;寄存器32-4000
movra REG
movai 0x40
movra H_8BIT
movai 0x00
movra L_8BIT
call SPI_Write
movai 33 ;寄存器33-3FC7
movra REG
movai 0x3F
movra H_8BIT
movai 0xC7
movra L_8BIT
call SPI_Write
movai 34 ;寄存器34-2000
movra REG
movai 0x20
movra H_8BIT
movai 0x00
movra L_8BIT
call SPI_Write
movai 35 ;寄存器35-0320
movra REG
movai 0x03
movra H_8BIT
movai 0x20
movra L_8BIT
call SPI_Write
movai 36 ;寄存器36-0380
movra REG
movai 0x03
movra H_8BIT
movai 0x80
movra L_8BIT
call SPI_Write
movai 37 ;寄存器37-0380
movra REG
movai 0x03
movra H_8BIT
movai 0x80
movra L_8BIT
call SPI_Write
movai 38 ;寄存器38-5A5A
movra REG
movai 0x5A
movra H_8BIT
movai 0x5A
movra L_8BIT
call SPI_Write
movai 39 ;寄存器39-0380
movra REG
movai 0x03
movra H_8BIT
movai 0x80
movra L_8BIT
call SPI_Write
movai 40 ;寄存器40-4401
movra REG
movai 0x44
movra H_8BIT
movai 0x01
movra L_8BIT
call SPI_Write
movai 41 ;寄存器41-B000
movra REG
movai 0xB0
movra H_8BIT
movai 0x00
movra L_8BIT
call SPI_Write
movai 42 ;寄存器42-FDB0
movra REG
movai 0xFD
movra H_8BIT
movai 0xB0
movra L_8BIT
call SPI_Write
movai 43 ;寄存器43-000F
movra REG
movai 0x00
movra H_8BIT
movai 0x0F
movra L_8BIT
call SPI_Write
movai 50 ;寄存器50-0000
movra REG
movai 0x00
movra H_8BIT
movai 0x00
movra L_8BIT
call SPI_Write
call DELAY_8MS
call DELAY_8MS
return 初始化完了之后,最后是启动,整体思路是先配置好基础配置,然后是寄存器52,清除发送指针,然后给寄存器50送值,最后启动发送:
movai 52 ;寄存器52-8000
movra REG ;清除发送指针
movai 0x80
movra H_8BIT
movai 0x00
movra L_8BIT
call SPI_Write
movai 50 ;寄存器50-55AA
movra REG ;发送55AA
movai 0x55
movra H_8BIT
movai 0xAA
movra L_8BIT
call SPI_Write
movai 7 ;寄存器7-0120
movra REG ;启动发送
movai 0x01
movra H_8BIT
movai 0x20
movra L_8BIT
call SPI_Write 第一次用无线的东西,我是看了官网的PDF,参考配置的,不知道思路对不对,PDF传上来跟官网程序传上来,官网的例子看不明白 {:sad:}自问自答,目前SPI写程序写进去以后,再读出来,写的跟读的是一样的值,说明SPI跟模块通讯正常 三楼的程序中,RST要重启,要不然收不到PKT会有,现在改了之后,PKT已经有一个110MS的低电平脉冲,就是现在频谱仪还没看到发射波形,继续调试
bclr SPI_RST ;SPI_RST=0关芯片寄存器值失去
call DELAY_1MS
bset SPI_RST ;SPI_RST=1开芯片
call DELAY_8MS
movai 52 ;寄存器52-8000
movra REG
movai 0x80
movra H_8BIT
movai 0x00
movra L_8BIT
call SPI_Write
movai 50 ;寄存器50-55AA
movra REG
movai 0x55
movra H_8BIT
movai 0xAA
movra L_8BIT
call SPI_Write
movai 7 ;寄存器7-0120
movra REG
movai 0x01
movra H_8BIT
movai 0x00
movra L_8BIT
call SPI_Write
call DELAY_8MS
页:
[1]