nRF24L01无线模块引脚检测MOSI值一直是0x0e和0x08 求解TT 100
我用pic24fv模块作为CPU的用设备检测nRF24L01MOSI信号一直显示0x0e和0x08程序如下:#include<p24fxxxx.h>#include"Co...
我用pic24fv模块作为CPU的 用设备检测nRF24L01 MOSI信号一直显示0x0e和0x08 程序如下:
#include <p24fxxxx.h>
#include "ComDef.h"
#include "PIC_nRF24L01.h"
#include "PIC_Delay.h"
#define MISO PORTBbits.RB13
#define MOSI PORTBbits.RB12
#define SCK PORTBbits.RB11
#define CE PORTBbits.RB14
#define CSN PORTBbits.RB10
//#define IRQ PORTBbits.RB5
uchar sta; // the status of nRF24L01
uchar Rx_Buf[ RX_PLOAD_WIDTH ]; // receive buffer
uchar TX_ADDRESS[ TX_ADR_WIDTH ] = {0x34,0x43,0x10,0x10,0x01}; // transport address
uchar RX_ADDRESS[ RX_ADR_WIDTH ] = {0x34,0x43,0x10,0x10,0x01}; // receive address
uchar Tx_Buf[ TX_PLOAD_WIDTH ] = {0xff};// transmit buff
uchar SPI_RW( uchar byte );
uchar SPI_Write_Buf( uchar reg, uchar *pBuf, uchar bytes );
void nRF24L01_IO_Init( void );
uchar SPI_Read( uchar reg )
{
uchar reg_val;
CSN=0;
SPI_RW(reg);
reg_val=SPI_RW( 0 );
CSN=1;
return( reg_val );
}
uchar SPI_RW_Reg( uchar reg, uchar value )
{
uchar status;
CSN=0;
status=SPI_RW(reg);
SPI_RW(value);
CSN=1;
return( status );
}
void TX_Mode( void )
{
nRF24L01_IO_Init();
SCK=0;
CSN=1;
CE=0;
SPI_RW_Reg(FLUSH_TX,0x00);
SPI_Write_Buf(WRITE_REG + TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH);
SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH);
SPI_RW_Reg(WRITE_REG + EN_AA, 0x01);
SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01);
SPI_RW_Reg(WRITE_REG + SETUP_RETR, 0x1a);
SPI_RW_Reg(WRITE_REG + RF_CH, 0x40);
SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x07);
SPI_RW_Reg(WRITE_REG + RX_PW_P0, RX_PLOAD_WIDTH);
SPI_RW_Reg(WRITE_REG + CONFIG, 0x0e);
CE=1;
delay_ms( 100 );
}
void Transmit( uchar* tx_buf )
{
CE=0;
SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH);
SPI_RW_Reg(FLUSH_TX,0x00);
SPI_Write_Buf(WR_TX_PLOAD, tx_buf, TX_PLOAD_WIDTH);
SPI_RW_Reg(WRITE_REG + CONFIG, 0x0e);
CE=1;
delay_ms(150);
}
uchar SPI_RW( uchar byte )
{
uchar bit_ctr;
for(bit_ctr=0;bit_ctr<8;bit_ctr++)
{
MOSI=( byte&0x80 );
byte=( byte<<1 );
SCK=1;
byte|=MISO;
//led=MISO;Delay(150);
SCK=0;
}
return( byte );
}
uchar SPI_Write_Buf( uchar reg, uchar *pBuf, uchar bytes )
{
uchar status,byte_ctr;
CSN = 0;
status = SPI_RW(reg);
for(byte_ctr=0; byte_ctr<bytes; byte_ctr++)
SPI_RW(*pBuf++);
CSN = 1;
return( status );
}
void nRF24L01_IO_Init( void )
{
TRISBbits.TRISB13 = 1;
TRISBbits.TRISB12 = 0;
TRISBbits.TRISB11 = 0;
TRISBbits.TRISB14 = 0;
TRISBbits.TRISB10 = 0;
} 展开
#include <p24fxxxx.h>
#include "ComDef.h"
#include "PIC_nRF24L01.h"
#include "PIC_Delay.h"
#define MISO PORTBbits.RB13
#define MOSI PORTBbits.RB12
#define SCK PORTBbits.RB11
#define CE PORTBbits.RB14
#define CSN PORTBbits.RB10
//#define IRQ PORTBbits.RB5
uchar sta; // the status of nRF24L01
uchar Rx_Buf[ RX_PLOAD_WIDTH ]; // receive buffer
uchar TX_ADDRESS[ TX_ADR_WIDTH ] = {0x34,0x43,0x10,0x10,0x01}; // transport address
uchar RX_ADDRESS[ RX_ADR_WIDTH ] = {0x34,0x43,0x10,0x10,0x01}; // receive address
uchar Tx_Buf[ TX_PLOAD_WIDTH ] = {0xff};// transmit buff
uchar SPI_RW( uchar byte );
uchar SPI_Write_Buf( uchar reg, uchar *pBuf, uchar bytes );
void nRF24L01_IO_Init( void );
uchar SPI_Read( uchar reg )
{
uchar reg_val;
CSN=0;
SPI_RW(reg);
reg_val=SPI_RW( 0 );
CSN=1;
return( reg_val );
}
uchar SPI_RW_Reg( uchar reg, uchar value )
{
uchar status;
CSN=0;
status=SPI_RW(reg);
SPI_RW(value);
CSN=1;
return( status );
}
void TX_Mode( void )
{
nRF24L01_IO_Init();
SCK=0;
CSN=1;
CE=0;
SPI_RW_Reg(FLUSH_TX,0x00);
SPI_Write_Buf(WRITE_REG + TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH);
SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH);
SPI_RW_Reg(WRITE_REG + EN_AA, 0x01);
SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01);
SPI_RW_Reg(WRITE_REG + SETUP_RETR, 0x1a);
SPI_RW_Reg(WRITE_REG + RF_CH, 0x40);
SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x07);
SPI_RW_Reg(WRITE_REG + RX_PW_P0, RX_PLOAD_WIDTH);
SPI_RW_Reg(WRITE_REG + CONFIG, 0x0e);
CE=1;
delay_ms( 100 );
}
void Transmit( uchar* tx_buf )
{
CE=0;
SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH);
SPI_RW_Reg(FLUSH_TX,0x00);
SPI_Write_Buf(WR_TX_PLOAD, tx_buf, TX_PLOAD_WIDTH);
SPI_RW_Reg(WRITE_REG + CONFIG, 0x0e);
CE=1;
delay_ms(150);
}
uchar SPI_RW( uchar byte )
{
uchar bit_ctr;
for(bit_ctr=0;bit_ctr<8;bit_ctr++)
{
MOSI=( byte&0x80 );
byte=( byte<<1 );
SCK=1;
byte|=MISO;
//led=MISO;Delay(150);
SCK=0;
}
return( byte );
}
uchar SPI_Write_Buf( uchar reg, uchar *pBuf, uchar bytes )
{
uchar status,byte_ctr;
CSN = 0;
status = SPI_RW(reg);
for(byte_ctr=0; byte_ctr<bytes; byte_ctr++)
SPI_RW(*pBuf++);
CSN = 1;
return( status );
}
void nRF24L01_IO_Init( void )
{
TRISBbits.TRISB13 = 1;
TRISBbits.TRISB12 = 0;
TRISBbits.TRISB11 = 0;
TRISBbits.TRISB14 = 0;
TRISBbits.TRISB10 = 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询