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

How to use ADuC812 SPI

Hello!
I tried to use the on-board SPI of the Analog Devices ADuC812
but I didn't managed it to work. No Data, no SCLK, the Pins
seemed all to be dead at all.
Maybe one of you can give me a hint or working sample code.

Thanks.

Here's some of my code:

// Initialize the SPI Interface

SPICON = 0x37;// configure SPI port for: 0011,0111 = 0x37
// Fosc/64, CPHA=1, CPOL=0, master
IE2 = 0x01; // enable SPI interrupt

EA = 1; // enable interrupts

...

void send_SPI(unsigned int byte)
{
SPIDAT = byte; // trigger data transfer
}


Parents
  • Hello all,

    I put your code in my aplication:
    #include <stdio.h> // declarations for I/O functions
    #include <ADuC812.h> // 8052 & ADuC812 predefined symbols

    // Variables globales
    bit flag_int=0; // Flag de la interrupcion
    unsigned char dato=0;

    sbit SS = P3^5; /* SFR for P3.5 */

    // Prototipos de funciones
    void spiTx(unsigned char txDat); // Transmit a byte data over the SPI
    unsigned char SPI_char( unsigned char c );

    //___________________________________________________________________
    // INTERRUPT SERVICE ROUTINE

    void spi_int () interrupt 7 { // ISPI*8+3 = 59dec = 3bhex = ISPI

    SS= 1; // complement SS (P3.5 on eval bd.)
    dato=dato+1;
    }

    /* END OF INT0 INTERRUPT ROUTINE */
    //____________________________________
    //___________________________________________________________________
    // INTERRUPT SERVICE ROUTINE

    void int0_int () interrupt 0 { // int0*8+3 = 0dec = 3hex = IE0

    flag_int=1; // Flag de detección INT0 externa
    P3 ^= 0x10; // complement LED (P3.4 on eval bd.)
    dato=dato+1;
    }

    /* END OF INT0 INTERRUPT ROUTINE */
    //___________________________________________________________________
    // MAIN PROGRAM

    void main (void)
    {


    /* CONFIGURE SPI */

    /* SPICON */

    SPE = 1; // SPI interface enable
    SPIM = 1; // SPI master mode operation
    CPOL = 0; // SPI CLOCK idles High
    CPHA = 0; // SPI leading SCLOCK edge to transmit data
    SPR1 = 1; // SPI clock rate SPR1 0 SPR0 0 for Fosc/4
    SPR0 = 1;

    /* CONFIGURACION DE LAS INTERRUPCIONES */

    EX0=1; // 1.- Habilitación Interrupcion externa 0
    PX0=1; // 2.- Interrupción externa 0 de alta prioridad
    IT0=1; // 3.- Interrupción externa 0 activa por flanco de bajada

    IE2=1; // Interrupcion Interrupcion SPI de fin de transmision


    EA=1; // Se permiten todas las interrupciones anteriormente programadas

    /* WAIT FOR INTERRUPTS */
    while (1)

    {

    // while (flag_int)
    // {
    // spiTx(dato); // Manda dato por SPI
    SPI_char(2);
    // flag_int=0; // Restauro el flag de la interrupcion

    // }


    } // endless loop

    }

    void spiTx(unsigned char txDat) // Transmit a byte data over the SPI
    {
    ISPI = 0; // Clear ISPI bit
    SS=0;
    SPIDAT = txDat;
    while(!ISPI); // Wait until tx complete
    }

    unsigned char SPI_char( unsigned char c )
    {
    ISPI = 0;
    SS=0;
    SPIDAT = c;
    while( !ISPI )
    {
    ; // do nothing but wait
    }
    return( SPIDAT );
    }

    I able to program clock and togle a port(I saw in osciloscope) but data does not flow thought MOSI line...

    Can anybody help me?

Reply
  • Hello all,

    I put your code in my aplication:
    #include <stdio.h> // declarations for I/O functions
    #include <ADuC812.h> // 8052 & ADuC812 predefined symbols

    // Variables globales
    bit flag_int=0; // Flag de la interrupcion
    unsigned char dato=0;

    sbit SS = P3^5; /* SFR for P3.5 */

    // Prototipos de funciones
    void spiTx(unsigned char txDat); // Transmit a byte data over the SPI
    unsigned char SPI_char( unsigned char c );

    //___________________________________________________________________
    // INTERRUPT SERVICE ROUTINE

    void spi_int () interrupt 7 { // ISPI*8+3 = 59dec = 3bhex = ISPI

    SS= 1; // complement SS (P3.5 on eval bd.)
    dato=dato+1;
    }

    /* END OF INT0 INTERRUPT ROUTINE */
    //____________________________________
    //___________________________________________________________________
    // INTERRUPT SERVICE ROUTINE

    void int0_int () interrupt 0 { // int0*8+3 = 0dec = 3hex = IE0

    flag_int=1; // Flag de detección INT0 externa
    P3 ^= 0x10; // complement LED (P3.4 on eval bd.)
    dato=dato+1;
    }

    /* END OF INT0 INTERRUPT ROUTINE */
    //___________________________________________________________________
    // MAIN PROGRAM

    void main (void)
    {


    /* CONFIGURE SPI */

    /* SPICON */

    SPE = 1; // SPI interface enable
    SPIM = 1; // SPI master mode operation
    CPOL = 0; // SPI CLOCK idles High
    CPHA = 0; // SPI leading SCLOCK edge to transmit data
    SPR1 = 1; // SPI clock rate SPR1 0 SPR0 0 for Fosc/4
    SPR0 = 1;

    /* CONFIGURACION DE LAS INTERRUPCIONES */

    EX0=1; // 1.- Habilitación Interrupcion externa 0
    PX0=1; // 2.- Interrupción externa 0 de alta prioridad
    IT0=1; // 3.- Interrupción externa 0 activa por flanco de bajada

    IE2=1; // Interrupcion Interrupcion SPI de fin de transmision


    EA=1; // Se permiten todas las interrupciones anteriormente programadas

    /* WAIT FOR INTERRUPTS */
    while (1)

    {

    // while (flag_int)
    // {
    // spiTx(dato); // Manda dato por SPI
    SPI_char(2);
    // flag_int=0; // Restauro el flag de la interrupcion

    // }


    } // endless loop

    }

    void spiTx(unsigned char txDat) // Transmit a byte data over the SPI
    {
    ISPI = 0; // Clear ISPI bit
    SS=0;
    SPIDAT = txDat;
    while(!ISPI); // Wait until tx complete
    }

    unsigned char SPI_char( unsigned char c )
    {
    ISPI = 0;
    SS=0;
    SPIDAT = c;
    while( !ISPI )
    {
    ; // do nothing but wait
    }
    return( SPIDAT );
    }

    I able to program clock and togle a port(I saw in osciloscope) but data does not flow thought MOSI line...

    Can anybody help me?

Children
No data