如题,我在2812芯片外围外扩了2片sja1000,但是在编写代码的过程中没有实现相应的功能,贴出来让大家帮忙看看
一下是原理图
SJA1000是一款地址/数据分时复用的芯片,我把他外扩在外部接口0上
现在的问题是我想操作一个寄存器,能不能用下面的代码实现呢?
比如**作地址0的寄存器 也就是0x2000
先通过宏
#define SJA_BASE_ADR 0x2000 //寄存器地址的基址
#define SJA_BASE_ADR_PTR *(volatile unsigned short int *)(SJA_BASE_ADR)
选好基址
以下是写的子函数
void Wr_SJA1_CMD ( Uint16 Wr_ADR )
{
//INTEL MODE,SJACS1=GPIOD0;SJA_ALE1=GPIOD1 ;SJACS2=GPIOA11;SJA_ALE2=GPIOA12
//GPIOD0=CS1,GPIOD1 =ALE1
GpioDataRegs.GPDCLEAR.bit.GPIOD0= 1; //CS1=GPIOD0,164245需要OE
GpioDataRegs.GPDSET.bit.GPIOD1 = 1; //WRITE ADRESS ALE1 =1=GPIOD1
SJA_BASE_ADR_PTR= Wr_ADR; //先送出地址,ALE=1
GpioDataRegs.GPDCLEAR.bit.GPIOD1 = 1; //WRITE ADRESS ALE1 CLEAR
GpioDataRegs.GPDSET.bit.GPIOD0 =1; //WRITE ADRESS SJA1
GpioDataRegs.GPDCLEAR.bit.GPIOD0= 1; //CS1
SJA_BASE_ADR_PTR= SJA_Wr_CMD;//按照地址写入状态信息 //然后再读数据,ALE0,CS=0,RD=0
GpioDataRegs.GPDSET.bit.GPIOD0=1 ;//WRITE ADRESS SJA2
}
再就是读的子程序
Uint8 Read_SJA1_Status ( Uint16 Read_ADR )
{
//INTEL MODE
GpioDataRegs.GPDCLEAR.bit.GPIOD0= 1; //CS1=GPIOD0,164245需要OE
GpioDataRegs.GPDSET.bit.GPIOD1 = 1; //WRITE ADRESS ALE1 =1=GPIOD1
SJA_BASE_ADR_PTR= Read_ADR; //先送出地址,ALE=1
GpioDataRegs.GPDCLEAR.bit.GPIOD1 = 1; //WRITE ADRESS ALE1 CLEAR
GpioDataRegs.GPDSET.bit.GPIOD0 =1; //WRITE ADRESS SJA1
GpioDataRegs.GPDCLEAR.bit.GPIOD0= 1; //CS1
SJA1_Status=SJA_BASE_ADR_PTR;//按照地址读出状态信息 //然后再读数据,ALE0,CS=0,RD=0
GpioDataRegs.GPDSET.bit.GPIOD0=1 ;//READ ADRESS SJA1
return SJA1_Status;
}
但是我发现,我读回来的数据不是我写进去的数据,不知道是编程的想法错了还是什么原因,请大家帮忙看看
|