SC16IS752在ARM擴(kuò)展串口中的應(yīng)用
5.初始化寄存器
SC16IS752初始化寄存器的程序如下:
/*SC16IS752初始化*/
void init_is752(void) {
/*初始化SC16IS752第一個(gè)串口A.*/
write_is752_rega(IS752_CH_A,IS752_LCR,0xbf); write_is752_rega(IS752_CH_A,IS752_EFR,IS752_EFR_VAL);
write_is752_rega(IS752_CH_A,IS752_LCR,0x00);
/*設(shè)置SC16IS752 串口A 中斷.*/
write_is752_rega(IS752_CH_A, IS752_IER, IS752_IER_VAL);
write_is752_rega(IS752_CH_A, IS752_FCR, IS752_FCR_VAL);
write_is752_rega(IS752_CH_A, IS752_MCR, IS752_MCR_VAL);
write_is752_rega(IS752_CH_A, IS752_EFCR, IS752_EFCR_VAL);
/*初始化SC16IS752第二個(gè)串口B,同串口A,略. 清寄存器程序,略*/
} /* 寫數(shù)據(jù) */
void write_is752_rega(unsigned char chx,unsigned char addr, unsigned char data){
unsigned char temp;
if((IS752_CH_A == chx) ||(IS752_CH_B == chx)){
CLR_IS752_CS;
temp = addr3;
temp |= chx;
spi_send_byte(SPI1,tmp);
spi_send_byte(SPI1,data); /*發(fā)送數(shù)據(jù).*/
SET_IS752_CS;
}
}
/*讀數(shù)據(jù)*/
unsigned char read_is752_rega(unsigned char chx, unsigned char addr){
unsigned char temp;
if((IS752_CH_A == chx) ||(IS752_CH_B == chx)){
CLR_IS752_CS;
temp = addr3;
temp |= 0x80|chx;
spi_send_byte(SPI1,temp);
spi_send_byte(SPI1,0xff);
SET_IS752_CS;
return(S1SPDR);
}
}
SPI程序接口在其他書籍中有詳細(xì)介紹,在此不作描述(見(jiàn)參考文獻(xiàn)1)。
評(píng)論