This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Need SPI read help

I've read the posts here, and searched the internet. How does one READ from a slave using a processor with SPI?

I can write just fine. I tell my slave that I'm going to write, then I put bits on the bus, and the processor sends out the data with each clock.

For reading, I tell my slave that I'm going to read... then when I read the input buffer, it is just equal to my "I'm going to read" instruction fed back to me.

How do I tell the processor to start sending clocks for a read so that my slave will start shifting out data??

If I can provide more details, please ask. Any reference to C code that reads from a slave over SPI, or any comments about what my stupid mistake is, would be greatly appreciated.

Thanks

Parents
  • We are developing a project with ADuC812 in Federal University of Campina
    Grande, and I wish to communicate two microconverters using the SPI. I have
    some problems becouse with the flag ISPI becouse the flag don't change in
    the
    end of the transmission. Is necessary to use any interrupt routine for to
    use
    the flag ISPI? I need more information about this problem. I am sending my
    code
    used for transmit a caracter C and to monitore the change in flag ISPI. I
    noted
    that the flag don't change. Please look my code, is it wrong?
    Send me some information, and if possible change the code.
    If possible, answer me how I may to transmit a byte in a master(
    micriconverter) for a slave(microconverter).


    Sincerely,
    Jaidilson Jó.

    //Master

    #include <aduc812.h>
    #include <stdio.h>
    #define SPICON_MR 0x33

    sbit P3_5 = 0xB5;
    sbit P3_4 = 0xB4;

    int i;

    void main ()
    {
    P3_5 = 1;

    // Serial
    SCON = 0x50;
    TMOD = 0x20;
    TR1 = 1;
    TH1 = 0xFD;

    IE2 = 0x01;
    IE = 0x81;
    TCON = 0x01;
    IT0 = 1;
    SPICON = SPICON_MR;

    P3_5 = 0;
    P3_4 = 0;

    SPIDAT = 'C'; //writing a character C for to transmit

    while((SPICON & 0x80) == 0)
    {
    TI=0;
    SBUF='\n';
    while(TI != 1){}
    printf("%\n",SPICON);
    while(TI!=1) { }
    }

    TI=0;
    SBUF='\n';
    while(TI != 1){}
    printf("%\n",SPICON);
    while(TI!=1) { }

    P3_4 = 1;
    P3_5 = 1;


    }

Reply
  • We are developing a project with ADuC812 in Federal University of Campina
    Grande, and I wish to communicate two microconverters using the SPI. I have
    some problems becouse with the flag ISPI becouse the flag don't change in
    the
    end of the transmission. Is necessary to use any interrupt routine for to
    use
    the flag ISPI? I need more information about this problem. I am sending my
    code
    used for transmit a caracter C and to monitore the change in flag ISPI. I
    noted
    that the flag don't change. Please look my code, is it wrong?
    Send me some information, and if possible change the code.
    If possible, answer me how I may to transmit a byte in a master(
    micriconverter) for a slave(microconverter).


    Sincerely,
    Jaidilson Jó.

    //Master

    #include <aduc812.h>
    #include <stdio.h>
    #define SPICON_MR 0x33

    sbit P3_5 = 0xB5;
    sbit P3_4 = 0xB4;

    int i;

    void main ()
    {
    P3_5 = 1;

    // Serial
    SCON = 0x50;
    TMOD = 0x20;
    TR1 = 1;
    TH1 = 0xFD;

    IE2 = 0x01;
    IE = 0x81;
    TCON = 0x01;
    IT0 = 1;
    SPICON = SPICON_MR;

    P3_5 = 0;
    P3_4 = 0;

    SPIDAT = 'C'; //writing a character C for to transmit

    while((SPICON & 0x80) == 0)
    {
    TI=0;
    SBUF='\n';
    while(TI != 1){}
    printf("%\n",SPICON);
    while(TI!=1) { }
    }

    TI=0;
    SBUF='\n';
    while(TI != 1){}
    printf("%\n",SPICON);
    while(TI!=1) { }

    P3_4 = 1;
    P3_5 = 1;


    }

Children
No data