Please read the previous posts about SPI communication. All the recent
people having problems with SPI communication are making the exact
same mistake.
You don't understand how UTXIFG0 works. It is set and cleared by
HARDWARE, and indicates that the TX Buffer is empty. However, data
might still be in the shift register. Basically, you are disabling the
slave before it has received the last 2 bytes you wrote to TXBUF.
You need to use RXIFG instead. Search through the posts discussing
SPI. TX empty flag will not work, as it sets before the last clock
edge on which the receiver reads the incomming data.
Regards,
Michael K.
--- In m..., "joshua" wrote:
>
> Hai frneds,
>
> Im using msp430f169 microcontroller for my project.
> The thing is im interfacing it with AT25040 EEPROM in SPI mode.Im not
> getting the which i send to U0TXBUF.While reading the data Im getting
> another data .For, Different address loctaiond im getting different
> data.This is how i Wrote code.Could some one guide me to read the data
> which i send to U0TXBUF into my U0RXBUF using SPI.
> #include
> void WriteEnb();
> void WriteReg();
> unsigned char ReadReg();
>
> void main()
>
> {
> P3SEL=0x0E;
> ME1=0x40;
> UCTL0=0x16;
> U0TCTL=0x62;
> U0BR0=0x02;
> U1BR0=0x00;
> U0MCTL=0X00;
>
> P3DIR=0x0F;
>
> while(1)
>
> { //P3OUT=0x0A;
> WriteEnb();
> WriteReg();
> ReadReg();
> // P3OUT=0x0B;
>
> }
>
> }
>
> void WriteEnb()
>
> {
>
> P3OUT=0X0A;
> IFG1 &=~UTXIFG0;
> U0TXBUF=0x06; //write enable
> while(!(IFG1 &UTXIFG0));
> //IFG1 &=~UTXIFG0;
> P3OUT =0x0B;
> }
>
> void WriteReg()
>
> {
>
> P3OUT =0X0A; //cs enabled
> // IFG1 &=~UTXIFG0;
> U0TXBUF=0x02; //write Instruction
> while(!(IFG1 & UTXIFG0));
> IFG1 &=~UTXIFG0;
> U0TXBUF=0x00; //address
> while(!(IFG1 & UTXIFG0));
> IFG1 &=~UTXIFG0;
> U0TXBUF=0xAA; //data
> while(!(IFG1 & UTXIFG0));
> P3OUT =0x0B; //cs disabled
>
> }
>
> unsigned char ReadReg()
> {
> char x;
> P3OUT=0x0A; //cs enabled
> // IFG1 &=~UTXIFG0;
> U0TXBUF=0x03; //read instruction
> while(!(IFG1 & UTXIFG0));
> IFG1 &=~UTXIFG0;
> U0TXBUF=0X00; //address
> while(!(IFG1 & UTXIFG0));
> IFG1 &=~UTXIFG0;
> U0TXBUF=0; //dummy byte
> while(!(IFG1 & UTXIFG0));
> IFG1 &=~URXIFG0;
> while(!(IFG1 & URXIFG0));
> x=U0RXBUF;
>
> P3OUT=0x0B;
>
> return x;
>
> }
>