DSPI Data Word aLignment MOD54415

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

DSPI Data Word aLignment MOD54415

Post by jediengineer »

Hi all,

I'm trying to address an AD7490 A2D converter with a MOD54415 using DSPI. I noticed in the setup instructions in dspi.h, it says "Transfers > 8 bits must be word aligned". But there's no other explanation of how to do this, because the DSPI driver is demanding bytes, even if the setup says I'm transferring 16 bits.

I have a logic analyzer attached to the board, and it shows that the data I'm sending is correct, and the returning data is also correct. However, when I output the data to MTTY, it's completely wrong. I've attached a screenshot of MTTY output (left side of pic) and the snippet of code that generates the output. My DSPI setup is as follows:

Code: Select all

DSPIInit(3, 1000000, 16, 0xF0, 0x0F, 0x01, 0x00, TRUE, 0, 0);
All my resulting values should be zero because my ADC inputs are pulled to ground. The upper nibble should reflect the ADC channel being converted and the lower 12 bits, the conversion value. So I should be seeing this:

0x0000
0x1000
0x2000
0x3000
...
0xF000


Not sure where I'm going wrong, can someone point me in the right direction?
Attachments
Untitled.png
Untitled.png (228.54 KiB) Viewed 3212 times
Ridgeglider
Posts: 513
Joined: Sat Apr 26, 2008 7:14 am

Re: DSPI Data Word aLignment MOD54415

Post by Ridgeglider »

Not sure about the dspi requirements, but this is how to align data. Say I wanted a struct to wrap around some standard types to meet some (usually) hardware requirements. Here are two versions that align and don't align data so it gets padded on specific boundaries. The aligned version forces data to the expected 4+4+2+1+2=13 byte size. Try sizeof() on the two versions and you will see the difference. You can also dump memory to see these alignments using the utility below.

struct __attribute__ ((__packed__)) AlignedData {
int intVar1 __attribute__ ( ( aligned( 4 ) ) ) ; //4 bytes
int intVar2 __attribute__ ( ( aligned( 4 ) ) ); //4 + 4 = 8 bytes
WORD wordVar3 __attribute__ ( ( aligned( 2 ) ) ); //8 + 2 = 10 bytes
BYTE byteVar4 __attribute__ ( ( aligned( 1 ) ) ); //10 + 1 = 11 bytes
WORD ADcount __attribute__ ( ( aligned( 4 ) ) ); //11 + 2 = 13 bytes
}

struct NonAlignedData {
int intVar1 ; //4 bytes
int intVar2 ; //4 + 4 = 8 bytes
WORD wordVar3 ; //8 + 2 = 10 bytes
BYTE byteVar4 ; //10 + 1 = 11 bytes
WORD ADcount ; //11 + 2 = 13 bytes --- NOPE!
}


Here's a modification of the NB ShowData() from utils.cpp that shows the addresses too:

Code: Select all

void ShowAddrAndData( PBYTE fromptr, unsigned int len )
{
// usage: ShowAddrAndData(  (PBYTE) BufToDump, NumBytesToDump ); 
   PBYTE pPos = fromptr;
   unsigned int left = len;
   unsigned int i;
   while ( left > 16 )
   {
      for ( i = 0; i < 16; i++ )
      {
         if( i == 0) {
         	iprintf( "%p: ", pPos);			// print addr 
         }
         iprintf( "%02x ", ( unsigned ) * ( pPos + i ) );
      }
      putchar( ' ' );
      for ( i = 0; i < 16; i++ )
      {
         char c = ( char ) ( *( pPos + i ) );
         if ( c < ' ' )
         {
            putchar( '.' );
         }
         else
         {
            putchar( c );
         }
      }
      putchar( '\r' );
      putchar( '\n' );
      pPos += 16;
      left -= 16;
      OSTimeDly(1);
   }
   for ( i = 0; i < left; i++ )
   {
		if( i == 0) {
        	iprintf( "%p: ", pPos ); 		// print addr
         }iprintf( "%02x ", ( unsigned ) * ( pPos + i ) );
   }
   for ( ; i < 16; i++ )
   {
      iprintf( " . " );
   }
   putchar( ' ' );
   for ( i = 0; i < left; i++ )
   {
      char c = ( char ) ( *( pPos + i ) );
      if ( c < ' ' )
      {
         putchar( '.' );
      }
      else
      {
         putchar( c );
      }
   }
   puts( "\n" );
}
For an overview of aligning data see: http://www-01.ibm.com/support/knowledge ... AP?lang=en
or http://www.ibm.com/developerworks/library/pa-dalign/


For details of the aligned attribute, see: http://www-01.ibm.com/support/knowledge ... ED?lang=en

for details of the packed attribute, see: http://www-01.ibm.com/support/knowledge ... ED?lang=en
Post Reply