Hi. This is with regards to ADuC7026. I am trying to interface the ADuC7026 to the digital potentiometer chip AD5235 using SPI. Data is 24-bit. I am using the software bitbang. I am able to write data to the SDI successfully. When I have to read the data from the SDO pin, I notice that I obtain the same data as the SDI. When I perform memory read operations, I get back the instruction that I send through the SDI instead of getting the data that is stored in that memory location. I am not sure what the problem could be. Please let me know what needs to be done with regards to this. This is really urgent! I'm attaching the read and write functions that I am currently using.
void SPIWrite(int local_SPI_data) { int count = 0; int outdata = 0x00; GP0CON = 0x00; //Enabling the logic low chip select pin GP0DAT = 0x10000000; // To provide delay before initializing the data and clock delay(48); // Setting P1.5 for the data and P1.7 for clock GP1CON = 0x00; //Clearing both bit 5(data)and bit 7(clock) GP1DAT = 0xA000 << 16; for(count = 0; count < 24; count++) { //Checking for the 24th bit in the input sequence outdata = ((local_SPI_data & 0x800000) ? 1 : 0); //Left-Shift the input sequence by 1 bit. This will be done 24 times local_SPI_data <<= 1; if (outdata == 1){ //Clock low, Data high GP1DAT = 0xA020<<16; delay(48); //Clock high, Data high GP1DAT = 0xA0A0<<16; delay(48); } else { //Clock low, data low GP1DAT = 0xA000<<16; delay(48); //Clock high, data low GP1DAT = 0xA080<<16; delay(48); } } //To provide time of 25 clock pulses delay(2400); Read_SDO(); } void Read_SDO() { int count = 0, p = 0, clk_count = 0, outdata = 0; int SDO_word = 0, SDO_data[24]; GP1CON = 0x00; while (clk_count < 24){ SDO_word =(GP1DAT & 0x00000040); SDO_data[clk_count] = SDO_word; clk_count++; } SDO_word = 0x00; for(p = 0; p < 24; p++){ SDO_word <<= 1; SDO_word |=(SDO_data[p]&0x40); } while(count < 24) { outdata = ((SDO_word & 0x800000)?1:0); if (outdata == 1){ //Clk low, SDO high GP1DAT = 0x8040 << 16; delay(48); //Clk high, SDO high GP1DAT = 0x80C0 << 16; delay(48); } else { //Clk low, SDO low GP1DAT = 0x8000 << 16; delay(48); //Clk high, SDO low GP1DAT = 0x8080 << 16; delay(48); } count++; } //Disable the logic low chip select pin GP0DAT = 0x10100000; } void delay(int length) { while(length>=0){ length--;} }
.
Thanks in advance!