MOD54415 SPI

for everything else
Post Reply
jediengineer
Posts: 192
Joined: Mon Dec 17, 2012 6:24 am

MOD54415 SPI

Post by jediengineer »

Does anyone have any code examples for using SPI? The \nburn\examples directory doesn't exactly help... I need to connect several devices, and I'm not quite sure how to set it all up. If it's in a book, can someone also point me to it? I didn't see it...

Thanks!!
tony
jediengineer
Posts: 192
Joined: Mon Dec 17, 2012 6:24 am

Re: MOD54415 SPI

Post by jediengineer »

Anyone?
versamodule
Posts: 14
Joined: Fri Jun 08, 2012 4:59 am

Re: MOD54415 SPI

Post by versamodule »

Have you gotten it to work with the example yet ?

All of my work is on the nano, so i am pulling from assumptions for the MOD.

In the example you have:

// J2[30].function(PINJ2_30_DSPI1_PCS0);
J2[25].function(PINJ2_25_DSPI1_SCK);
J2[27].function(PINJ2_27_DSPI1_SIN);
J2[28].function(PINJ2_28_DSPI1_SOUT);

// I am assuming that the commented line above is taken care of when you call DSPIInit(); to set it up, if not then uncomment it.

So bare bones example you would have (including the set up stuff as in the example of course).


DSPIInit();

// Just put some data so watch on scope.
TXBuffer[0]=0xaa;
TXBuffer[1]=0x55;

// Send data via DSPI
DSPIStart(DEFAULT_DSPI_MODULE, TXBuffer, RXBuffer, 2, &DSPI_SEM);

// Wait for DSPI to complete
OSSemPend( &DSPI_SEM, 0 );


Thats it... if talking to say an A/D converter and you want to read what it send back then its already in the RXBuffer.
If the A/D sends back 16 bits this is how you would read it back (assuming MSB first).

unsigned int value;

value = (unsigned int)RXBuffer[0]<< 8;
value |= RXBuffer[0];

printf("Value=%u\r\n",value);
jediengineer
Posts: 192
Joined: Mon Dec 17, 2012 6:24 am

Re: MOD54415 SPI

Post by jediengineer »

So far, I haven't been able to test any code yet - I'm waiting for my development board to come back from being made (custom). Keep in mind as you read through my posts that I'm re-acquainting myself with this because I haven't touched this stuff in over 10 years - the last one I used was a PIC or Atmel chip, all programmed in assembly. Suddenly I found myself thrust into this world again so I'm kinda re-learning on the fly. Not all of it is lost on me, just a few concepts. As far as software, this is my setup so far:

// SPI initialization:
// SPI 1 for GPIO breakout
J2[27].function(3); //SPI 1 Input
J2[28].function(3); //SPI 1 Out
J2[30].function(3); //SPI 1 chip select 0
J2[25].function(3); //SPI 1 clock

//SPI 2 for ADC
J2[21].function(3); //SPI 3 Input
J2[22].function(3); //SPI 3 Out
J2[23].function(3); //SPI 3 chip select 0
J2[24].function(3); //SPI 3 clock

DSPIInit();

Like yourself, I'm not sure if the DPIInit() function manages the the PCS0 pin, but I set it anyways. I'm looking over he code, and I'm also looking at the DSPI2SERIAL example as well, and am taking apart the headers to see how this stuff works. I am driving a 16 input ADC with SP as well as a GPIO breakout box for ease of controlling muxes. So I'm using SPI1 and SPI3 respectively. I'm attempting to set up the ADC to convert all at once, then I'll go through and read all the data into an array with an ID code attached. That's basically it. But writing to and reading from SPI is proving itself a challenge to set up and furthermore to understand.
Post Reply