SPI problem in P89v51RD2

Discussion in 'Embedded Systems and Microcontrollers' started by aquib, Mar 6, 2008.

  1. aquib

    Thread Starter New Member

    Feb 26, 2007
    2
    0
    I am using a P89V51RD2, which is a controller from NXP. I am having problems using the SPI protocol to communicate with a serial EEPROM.
    I have stripped down the code to bare basics for troubleshooting and to identify the problem.
    I have found that when i am testing for the SPIF flag, which indicates a successful data transfer, the program execution gets stuck at this point and does not proceed further.
    I have used Leds for troubleshooting. The code which i am working with is as below. LED2 never glows as the code gets stuck at while (!(SPCFG & 0x80));

    If any one can help me find a solution it will be great
    CODE

    /************************************************* ****************************************/
    //Program: Interfacing AT93C46A serial EEPROM to a P89V51RD2 using the SPI//
    /************************************************* ****************************************/


    #include <stdio.h>
    #include <p89v51rx2.h>

    //SPI Pin Defination
    sbit cs = P1^4;
    sbit di = P1^5;
    sbit dou = P1^6;
    sbit clk = P1^7;

    //Debugging LEDs
    sbit LED1 = P2^0;
    sbit LED2 = P2^1;

    //DELAY FUNCTIONS
    //delay(10) = 200usec.

    void delay(unsigned char Delval)
    {
    unsigned char i=25;
    for(;Delval!=0;Delval--)
    for(;i!=0;i--);
    }

    void delay_ms(unsigned int Delval_ms)
    {
    for(;Delval_ms!=0;Delval_ms--)
    {
    delay(250);
    delay(250);
    delay(250);
    delay(250);
    }
    }
    //MAIN
    void main(void)
    {

    LED1 = 0;
    LED2 = 0;

    cs = 1;
    di = 1;
    dou = 1;
    clk = 1;
    delay_ms(10);

    LED1 = 1; // Start of SPI
    SPCTL = 0x73; //initialize SPI
    SPDAT = 0x05;
    while (!(SPCFG & 0x80));
    LED2 = 1; // End of SPI transfer

    while(1){}
    }
     
  2. all.go_rhythm

    New Member

    Dec 18, 2008
    1
    0
    Hi aquib....

    I had a doubt, u said ur using "P89V51RD2" but the code u had given is not for this controller....logic used in this code is applicable to ur controller but u are supposed to change the register names...

    simply remove,

    SPCTL and past SPCR
    SPCFG and past SPSR

    I hope this works.....DO tell the result.....



     
  3. futz

    Member

    Dec 14, 2008
    23
    0
    Shouldn't you be using a logical AND (&&) there rather than a bitwise AND (&)?

    EDIT: I don't think that would break it. I just noticed I did the same thing in some working SPI code for my ARM7 the other day. All fixed now.
     
    Last edited: Dec 21, 2008
  4. gayaabhi

    New Member

    Oct 7, 2009
    1
    0
    Hi!
    I am having doubt that i want to use P89V51RD2 to communicate with my ethernet controller AX11015. Iwant to send some data from my micro controller to the ethernet controller through SPI. Is it necessary to interface EEPROM. or how is it possible..If possible send me a simple SPI code to communicate between two 8051 controllers..please help its a part of my final year project....
     
Loading...