公司旧项目供应商使用MSP430F5438控制LT8920射频模块做遥控通讯,因原供应商主程序问题,目前转为自己开发程序,供应商不提供原始代码。目前在配置LT8920时无法初始化,请各位大佬看看,这个LT8920模块要怎样驱动起来
单片机源程序如下:
pin脚配置
- P1DIR |= BIT0 ; //IR -> RST
- P1OUT &= ~BIT0 ; //DEFAULT SET LOW
- P5DIR |= BIT0 ; //CS -> SPI_CLK
- P5OUT &= ~BIT0 ; //DEFAULT SET LOW
- P6DIR |= BIT7 ; //SC -> SPI_SS
- P6OUT |= BIT7 ; //DEFAULT SET HIGH
- P7DIR |= BIT4 ; //MO -> MOSI
- P7OUT &= ~BIT4 ; //DEFAULT SET LOW
- P7DIR &= ~(BIT5 + BIT6) ; //MI -> MISO
- //CE -> PKT
复制代码 宏定义
- #define RST(x) (x)? (P1OUT |= BIT0) : (P1OUT &= ~BIT0)
- #define SPI_SS(x) (x)? (P6OUT |= BIT7) : (P6OUT &= ~BIT7)
- #define SPI_CLK(x) (x)? (P5OUT |= BIT0) : (P5OUT &= ~BIT0)
- #define MOSI(x) (x)? (P7OUT |= BIT4) : (P7OUT &= ~BIT4)
- #define MISO (P7IN & BIT5)
- #define PKT (P7IN & BIT6)
复制代码 写寄存器
- void SPI_WriteReg(unsigned char addr, unsigned char H, unsigned char L)
- {
- int i;
- SPI_SS(OFF);
- delay_us(5);
- for(i = 0; i < 8; ++ i)
- {
- MOSI((addr & 0x80));
- delay_us(5);
- SPI_CLK(ON);
- delay_us(5);
- SPI_CLK(OFF); //capturing at the down side
- delay_us(5);
- addr = addr << 1; //There is no Delay here. determines the rate of SPI.
- }
- for(i = 0; i < 8; ++i) //Write H
- {
- MOSI((H & 0x80));
- delay_us(5);
- SPI_CLK(ON);
- delay_us(5);
- SPI_CLK(OFF); //capturing at the down side
- delay_us(5);
- H = H << 1;
- }
- for(i = 0; i < 8; ++i) //Write L
- {
- MOSI((L & 0x80));
- delay_us(5);
- SPI_CLK(ON);
- delay_us(5);
- SPI_CLK(OFF); //capturing at the down side
- delay_us(5);
- L = L << 1;
- }
- SPI_SS(ON);
- delay_us(5);
- }
复制代码
读寄存器
- void SPI_ReadReg(unsigned char addr)
- {
- int i;
- SPI_SS(OFF);
- delay_us(5);
- //addr += 0x80; //when reading a Register,the Address should be added with 0x80.
- addr |= 0x80; //bit7 1:read,0:write
- for(i = 0; i < 8; ++ i)
- {
- MOSI((addr & 0x80));
- delay_us(5);
- SPI_CLK(ON);
- delay_us(5);
- SPI_CLK(OFF); //capturing at the down side
- delay_us(5);
- addr = addr << 1; //Move one bit to the left.
- }
- for(i = 0; i < 8; ++ i)
- {
- SPI_CLK(ON);
- delay_us(5);
- SPI_CLK(OFF); //capturing at the down side
- delay_us(5);
-
- RegH = RegH << 1;
- RegH |= MISO;
- }
-
- for(i = 0; i < 8; ++ i)
- {
- SPI_CLK(ON);
- delay_us(5);
- SPI_CLK(OFF); //capturing at the down side
- delay_us(5);
- RegL = RegL << 1;
- RegL |= MISO;
- }
- SPI_SS(ON);
- delay_us(5);
- }
复制代码
LT8920初始化
- void LT8900_Init(void)
- {
- RST(OFF);
- delay_ms(4); //delay 4ms
- RST(ON);
- delay_ms(8); //delay 8ms for 晶振稳定
-
- SPI_WriteReg( 0, 0x6f, 0xef ); //default
- SPI_WriteReg( 1, 0x56, 0x81 ); //default
- SPI_WriteReg( 2, 0x66, 0x17 ); //default 6619/6617
- SPI_WriteReg( 4, 0x9c, 0xc9 ); //default 5447/9cc9
- SPI_WriteReg( 5, 0x66, 0x37 ); //default f000/6637
- SPI_WriteReg( 7, 0x00, 0x00 ); //channel is 2402Mhz
- SPI_WriteReg( 8, 0x6c, 0x90 ); //default 71af/6c90
- SPI_WriteReg( 9, 0x48, 0x00 ); //PA -12.2dbm
- SPI_WriteReg(10, 0x7f, 0xfd ); //Crystal osc. enable
- SPI_WriteReg(11, 0x00, 0x08 ); //RSSI enabled
- SPI_WriteReg(12, 0x00, 0x00 ); //default
- SPI_WriteReg(13, 0x48, 0xbd ); //default
- SPI_WriteReg(22, 0x00, 0xff ); //default
- SPI_WriteReg(23, 0x80, 0x05 ); //Calibrate VCO before each and every Tx/Rx.
- SPI_WriteReg(24, 0x00, 0x67 ); //default
- SPI_WriteReg(25, 0x16, 0x59 ); //default
- SPI_WriteReg(26, 0x19, 0xe0 ); //default
- SPI_WriteReg(27, 0x13, 0x00 );
- SPI_WriteReg(28, 0x18, 0x00 ); //default
- SPI_WriteReg(32, 0x48, 0x00 ); //8920在62.5kbps下同步头只能是32或16bit
- SPI_WriteReg(33, 0x3f, 0xc7 ); //Configures packet sequencing
- SPI_WriteReg(34, 0x20, 0x00 ); //Configures packet sequencing
- SPI_WriteReg(35, 0x05, 0x00 ); //Auto Ack max Tx retries = 4
- SPI_WriteReg(36, 0x03, 0x80 ); //sync word
- SPI_WriteReg(37, 0x03, 0x80 ); //sync word
- SPI_WriteReg(38, 0x5a, 0x5a ); //sync word
- SPI_WriteReg(39, 0x03, 0x80 ); //sync word
- SPI_WriteReg(40, 0x44, 0x02 ); //Configure FIFO flag, sync threshold, 1bit可错
- SPI_WriteReg(41, 0xb8, 0x00 ); /*CRC is ON; scramble is OFF; AUTO_ACK is ON*/
-
- SPI_WriteReg(42, 0xfd, 0xb0 ); /*等待RX_ACK时间 176us*/
-
- SPI_WriteReg(43, 0x00, 0x0f );
- SPI_WriteReg(44, 0x10, 0x00 );
- SPI_WriteReg(45, 0x05, 0x52 ); //62.5Kbps
- SPI_WriteReg(50, 0x00, 0x00 );
- delay_ms(100);
- }
复制代码
主程序初始化后再读寄存器,无法正确读取,无法确认是初始化不成功还是读取不成功
- LT8900_Init( );
- //读出寄存器的值检查硬件读写时序是否正确
- SPI_ReadReg(40);
- if ((RegH==0x44) && (RegL==0x02))
- {
- //NIGHTLIGHT(ON);
- LED_P(ON);
- //Delay_ms(200);
- //__delay_cycles(160000);
- //NIGHTLIGHT(OFF);
- Uart0_Send(Welcome,12);
- }
- else
- //LED_P(ON);
- NIGHTLIGHT(ON);
复制代码
|