Hello,
I'm using the Atmel AT91SAM7X256 with NUT/OS 4.8.2 on my OLIMEX SAM7-EX256 board for my recent project. I already programmed the SPI bus for the integrated Nokia display on the board.
What I am now trying to do is reading the contents of some registers from an externel IC via SPI. These registers are 8 bit wide and habe addresses from 0x00 to 0x1F (5 bits). To read a register from the IC you have to send a command to the IC: 0x40 + address. For Example: to read register 0x01 you must send 0x41.
To test my software i'm just reading out the contents of each register in a for-loop:
Code:
for(i=0; i<=0x1F; i++){
spi_rec = ic_readSingleRegister(i);
printf("Register 0x%X: 0x%X \n", i, spi_rec);
}
The output of the printf-function goes to the uart port and then to a terminal-program.
My problem now is, that the contents of the registers which are read in this loop are all correct but they do not correpond to the right address. In fact they are all shifted one address so that the content of register 0x00 will be displayed as the content of register 0x01.
If you take a look at the screenshot with all 4 bus lines, you can see that the signals on the bus are correct. The external IC anwers correctly. The content of register 0x01 is 0x06 (see MISO line). But the output in the terminal program will say that 0x06 is the content of register 0x02.
If I'm running the program in debug the output is correct and so I am not able to find any error...
Here is the source code of the used functions:
Code:
unsigned char ic_readSingleRegister(unsigned char address){
unsigned char temp;
if(address > 0x1F) return 0;
temp = 0x40;
temp += address;
spi1_sendByte(temp);
temp = 0x00;
temp = spi1_receiveByte();
return (temp);
}
void spi1_sendByte(unsigned char data){
volatile AT91PS_SPI pSPI = AT91C_BASE_SPI1;
while(!(pSPI->SPI_SR & AT91C_SPI_TDRE));
pSPI->SPI_TDR = data & 0x00FF
}
unsigned char spi1_receiveByte(void){
volatile AT91PS_SPI pSPI = AT91C_BASE_SPI1;
unsigned char temp;
spi1_sendByte(0xFF); //zuerst byte senden
while(!(pSPI->SPI_SR & AT91C_SPI_RDRF));
temp = (pSPI->SPI_RDR & 0x00FF);
return(temp);
}
I hope that anybody can help me because I'm working on this for nearly two weeks now and still got no fix...
Thank you very much for your answers!
Greetings from Germany,
Markus