Skip to main content
Visitor II
May 29, 2007
Question

Why can't I read data from the SPI slave device?

  • May 29, 2007
  • 2 replies
  • 709 views
Posted on May 29, 2007 at 14:08

Why can't I read data from the SPI slave device?

    This topic has been closed for replies.

    2 replies

    sunsyAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 12:08

    I used upsd3354D with TC72(Microchip) , the SPITXD and SPICLK works well. But, I can't READ any byte from the slave device, the SPIRXD keeps high all the time.

    e.g. Read the TC72 ID (0x54), but I read 0xFF.

    unsigned char ReadTemperID(void)

    { unsigned char t_id;

    P1_7=1;

    while (SPISTAT & SPI_BUSY_FLAG); //Waiting if SPI is busy

    SPICON0|=RE;

    while (!(SPISTAT & SPI_TI_FLAG)); //Waiting if SPI transfer is full

    SPITDR=0x00; //Send 0x02 to select temper MSB byte

    while (!(SPISTAT & SPI_TRANSMIT_END_FLAG));

    while (!(SPISTAT & SPI_RI_FLAG));

    SPITDR=SPI_Dummy; //Provide read clock by sending a dummy byte

    while (!(SPISTAT & SPI_TRANSMIT_END_FLAG)); //Waiting if SPI transfer is full

    while (!(SPISTAT & SPI_RI_FLAG)); //Waiting if SPI receiver is empty

    t_id=SPIRDR; //Read data from SPIRDR register

    SPICON0&=(~RE); //Disable SPI receiver

    P1_7=0;

    return(t_id); //Return data received

    }

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 12:08

    I actually have the same problem with the 24LC640. Even when I attempt to read the internal registry I get 0xFF.