Content originally posted in LPCWare by eddiemallon on Tue Feb 02 13:53:43 MST 2016
Hi, I design some hardware with a 2129 interfaced to an AD7707. I did originally have problems trying to interface to the AD7707 due to lack of information. Eventually I did get it to work. Below are the sections of code to initiate the SPI, and transmit and receive from the AD7707. CS was connected to 0v to enable device permanently. Hope it helps.
void init_board (void)
{
PINSEL0 = 0x00005105;//En Pin 0.0,1 as UART TxD RxD; SPI_1 Pin 0.4,6,7
PINSEL1 = 0x000002A8;//En SPI_2 Pin 0.17,18,19,20
IODIR0 = 0x00400f00;//set P0.8,9,10,11, 22 to o/ps
}
void init_SPI (void)
{
S0SPCCR = 0x96;//Set SPI_1 clk to 98kHz
S0SPCR = 0x20;//Set SPI_1 to master, MSB first, SCK active low.
IOSET0 = 0x00400A00;//set P0.11, 22 to 'Hi'; P0.8 to '0', P0.9 to '1' : 4-20mA
S1SPCCR = 0x96;//Set SPI_2 clk to 98kHz
S1SPCR = 0x38;//Set SPI_2 to master, MSB first, SCK active high.
}
void AD7707_tx(void)
{
S1SPDR = AD7707_tx_data;//write data
while (S1SPSR != 0x80);//Wait for data sent; check SR bit7 is 'Hi'
}
void AD7707_rx(void)
{
AD7707_tx_data = 0x38;
AD7707_tx();
do
AD7707_drdy =IOPIN0;
while ((AD7707_drdy & 0x00200000) !=0);
AD7707_tx_data = 0x00;// data rqst
AD7707_tx();
rxdata_H = S1SPDR;
AD7707_tx_data = 0x00; // data rqst
AD7707_tx();
rxdata_L = S1SPDR;
AD7707_rx_data = ((rxdata_H <<8) | rxdata_L);
}
void init_AD7707(void)
{
IOCLR0 = 0x00400000;// reset AD7707 po.22
delay2();
IOSET0 = 0x00400000;
AD7707_tx_data = 0x20;//write data to Comm Reg: An1_Locom selected.
AD7707_tx();
AD7707_tx_data = 0x1c;//write data to Clk Reg:
AD7707_tx();
AD7707_tx_data = 0x10;//write data to Comm Reg: An1_Locom selected.
AD7707_tx();
AD7707_tx_data = 0x44;//write data to SetUp Reg: An1_Locom selected, unipolar.
AD7707_tx();
}