[En-Nut-Discussion] EVK1100 SPI Slave

philippgl at freenet.de philippgl at freenet.de
Fri Oct 10 15:30:43 CEST 2014


Hi Thiago,
yes sorry my mailprogramm screwed the code up:

Here is a working example:
You just need to replace the spibus0 path and compile it!
So if i run that code the Spi Frequency stays at around 6-7kHz no matter what i initialize in the NUTSPINODE....

I hope the code works for you!

#include 
/* Device specific definitions. */
#include 
#include 
#include 

/* OS specific definitions. */
#include 
#include 
#include 

/* Standard C header files. */
#include 
#include 

/*Globale Variablen*/
#include 


int rc;

NUTSPINODE my_node = {
    &spiBus0Avr32,             /* Pointer to the bus controller driver. */
    NULL,                     /* Optional pointer to device specific settings. */
    10000,                     /* SPI clock rate. */
    0,                         /* SPI mode */
    8,                         /* SPI data bits. */
    1                         /* Chip select index. */
};

int MyInit(void)
{
    rc = Avr32SpiBusNodeInit(&my_node);
     
    if (rc == 0) {
        NutEventPost(&spiBus0Avr32.bus_mutex);
    }
    return rc;
}

     
int MyTransfer(uint8_t *buf, int len)
{    
    
    rc = Avr32SpiBus0Select(&my_node, NUT_WAIT_INFINITE);
    if (rc == 0) {
        rc =  Avr32SpiBus0Transfer(&my_node, buf, NULL, len);
    }
    Avr32SpiBus0Deselect(&my_node);
    return rc;
}

int main(void)
{
    
    uint8_t *tx;
    
    tx = (uint8_t*) malloc(10);
    
    int i = 0;
    
    MyInit();
    
    for(i=0;i<10;i++){                        //SPI BUFFER
        tx[i] = 0xAA;
    }
    
    for(;;){
    
        MyTransfer(tx,10);
        
     }
        
    return 0;        
}








---
Alle Postfächer an einem Ort. Jetzt wechseln und E-Mail-Adresse mitnehmen! http://email.freenet.de/basic/Informationen




More information about the En-Nut-Discussion mailing list