为了指向外发送24bits的数据,本人配置EPI0如下:
void EPI_initial(void){
volatile unsigned long waitpoint;
SYSCTL_RCGC1_R |=SYSCTL_RCGC1_EPI0;//0100 0000B RCGC1.30 used to enable EPI function
waitpoint = SYSCTL_RCGC1_R; //wait 2 instruction cycles, to effect RCGC1
SYSCTL_RCGC2_R |=SYSCTL_RCGC2_GPIOB|SYSCTL_RCGC2_GPIOC|SYSCTL_RCGC2_GPIOD|SYSCTL_RCGC2_GPIOE\
|SYSCTL_RCGC2_GPIOH|SYSCTL_RCGC2_GPIOG|SYSCTL_RCGC2_GPIOJ;
//PC PD PE PG PH PJ enable clock to appropriat GPIO module
waitpoint = SYSCTL_RCGC2_R; //wait 2 instruction cycles, to effect RCGC2
//port c
GPIO_PORTC_AFSEL_R|=0xf0;//11110000B=0xf0 PC4 PC5 PC6 PC7 set as EPI
GPIO_PORTC_PUR_R |= 0xf0;//pull up
GPIO_PORTC_DR2R_R&=~(0xf0);
GPIO_PORTC_DR2R_R|=0x0f0;//set 2mA drive
GPIO_PORTC_DR4R_R|=0x00;
GPIO_PORTC_DR8R_R|=0x00;
GPIO_PORTC_PCTL_R&=0x0000ffff;//
GPIO_PORTC_PCTL_R|=0x88880000;//
//port d
GPIO_PORTD_AFSEL_R|=0x1c;//00011100B=0x1c PD2 PD3 PD4 set as EPI
GPIO_PORTD_PUR_R |= 0x1c;//pull up
GPIO_PORTD_DR2R_R&=~(0x1c);
GPIO_PORTD_DR2R_R|=0x1c;//set 2mA drive
GPIO_PORTD_DR4R_R|=0x00;
GPIO_PORTD_DR8R_R|=0x00;
GPIO_PORTD_PCTL_R&=0xfff000ff;//
GPIO_PORTD_PCTL_R|=0x00088800;//
//port e
GPIO_PORTE_AFSEL_R |= 0x03;//00000011B=0x03 PE0 PE1 set as EPI
GPIO_PORTE_PUR_R |= 0x03;
GPIO_PORTE_DR2R_R&=~(0x03);
GPIO_PORTE_DR2R_R|=0x03;//set 2mA drive
GPIO_PORTE_DR4R_R|=0x00;
GPIO_PORTE_DR8R_R|=0x00;
GPIO_PORTE_PCTL_R&=0xffffff00;//
GPIO_PORTE_PCTL_R|=0x00000088;//
//port f
GPIO_PORTF_AFSEL_R|=0x30;//00110000B=0x30 PF4 PF5set as EPI
GPIO_PORTF_PUR_R |=0x30;
GPIO_PORTF_DR2R_R&=~(0x30);
GPIO_PORTF_DR2R_R|=0x30;//set 2mA drive
GPIO_PORTF_DR4R_R|=0x00;
GPIO_PORTF_DR8R_R|=0x00;
GPIO_PORTF_PCTL_R&=0xff00ffff;//
GPIO_PORTF_PCTL_R|=0x00880000;//
//port g
GPIO_PORTG_AFSEL_R|=0x03;//00000011B=0x03 PG0 PG1 set as EPI
GPIO_PORTG_PUR_R |= 0x03; //pull up
GPIO_PORTG_DR2R_R&=~(0x03);
GPIO_PORTG_DR2R_R|=0x03;//set 2mA drive
GPIO_PORTG_DR4R_R|=0x00;
GPIO_PORTG_DR8R_R|=0x00;
GPIO_PORTG_PCTL_R&=0xffffff00;//
GPIO_PORTG_PCTL_R|=0x00000088;//
//port h
GPIO_PORTH_AFSEL_R|=0x3f;//00111111B=0x3f PH0 PH1 PH2 PH3 PH4 PH5 set as EPI
GPIO_PORTH_PUR_R |= 0x3f; //pull up
GPIO_PORTH_DR2R_R&=~(0x03f);
GPIO_PORTH_DR2R_R|=0x3f;//set 2mA drive
GPIO_PORTH_DR4R_R|=0x00;
GPIO_PORTH_DR8R_R|=0x00;
GPIO_PORTH_PCTL_R&=0xff000000;//
GPIO_PORTH_PCTL_R|=0x00888888;//
//port j
GPIO_PORTJ_AFSEL_R|=0x07;//00000111B=0x03 PJ0 PJ1 PJ2 set as EPI
GPIO_PORTJ_PUR_R |= 0x07;
GPIO_PORTJ_DR2R_R&=~(0x07);
GPIO_PORTJ_DR2R_R|=0x07;//set 2mA drive
GPIO_PORTJ_DR4R_R|=0x00;
GPIO_PORTJ_DR8R_R|=0x00;
GPIO_PORTJ_PCTL_R&=0xfffff000;//
GPIO_PORTJ_PCTL_R|=0x00000888;//
//EPI register
//General custom interfaces of any speed
EPI0_CFG_R = EPI_CFG_BLKEN|EPI_CFG_MODE_NONE;//.EPI enable, general purpose
EPI0_BAUD_R = 0x00000002;//EPI clock freq = (system clock freq)/4
// EPI0_SDRAMCFG_R = 0x42ee0000; //20MHz
// EPI0_HB8CFG_R = 0x00000000;
// EPI0_HB16CFG_R = 0x00000000;
EPI0_GPCFG_R = EPI_GPCFG_CLKPIN|EPI_GPCFG_CLKGATE|EPI_GPCFG_RW|EPI_GPCFG_WR2CYC\
|EPI_GPCFG_RD2CYC|EPI_GPCFG_MAXWAIT_M|EPI_GPCFG_DSIZE_24BIT;
//EPI31 as clock, RW, WR2CYC=1 RD2CYC=1,ASIZE=0, DSIZE=2(24bits)
//EPI0_HB8CFG2_R = 0x00000000;
//EPI0_HB16CFG2_R = 0x00000000;
EPI0_GPCFG2_R = EPI_GPCFG2_WORD&0x00000000;//for 24bits, WORD must be clear
EPI0_ADDRMAP_R = EPI_ADDRMAP_EPADR_A000;//external peripheral address 0xa0000000
EPI0_RSIZE0_R = EPI_RSIZE0_SIZE_32BIT;
EPI0_RSIZE1_R = EPI_RSIZE1_SIZE_32BIT;
EPI0_RADDR0_R = EPI_RADDR0_ADDR_M;
EPI0_RADDR1_R = EPI_RADDR1_ADDR_M;
EPI0_RPSTD0_R = EPI_RPSTD0_POSTCNT_M;
EPI0_RPSTD1_R = EPI_RPSTD1_POSTCNT_M;
//EPI0_STAT_R = 0x00000000; //read only
//EPI0_RFIFOCNT_R = 0x00000000; //read only
//EPI0_READFIFO_R = 0x00000000; //read only
//EPI0_READFIFO1_R = 0x00000000; //read only
//EPI0_READFIFO2_R = 0x00000000; //read only
//EPI0_READFIFO3_R = 0x00000000; //read only
//EPI0_READFIFO4_R = 0x00000000; //read only
//EPI0_READFIFO5_R = 0x00000000; //read only
//EPI0_READFIFO6_R = 0x00000000; //read only
//EPI0_READFIFO7_R = 0x00000000; //read only
EPI0_FIFOLVL_R = EPI_FIFOLVL_WRFIFO_EMPT|EPI_FIFOLVL_RDFIFO_EMPT;
EPI0_WFIFOCNT_R = EPI_WFIFOCNT_WTAV_M;
EPI0_IM_R = EPI_IM_WRIM|EPI_IM_ERRIM; //EPI interrupt disable
//EPI0_RIS_R = 0x000004; //read only
//EPI0_MIS_R = 0x00000000; //read only
EPI0_EISC_R = EPI_EISC_WTFULL;
}
希望高手帮我指点,谢谢先。 |