[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RV: SPI




Hi Johan,

Did you get any advance with the SSP driver?
My program attempts to write continuously to the SPI (3 bytes each
write), but write blocks in the third write. I get this output:
 
Trying to send 3 bytes...
3 bytes Written: 3, 14, 0
Trying to read 3 bytes...
3 bytes Read: 255, 255, 255
Trying to send 3 bytes...
3 bytes Written: 3, 14, 0
Trying to read 3 bytes...
3 bytes Read: 0, 255, 255
Trying to send 3 bytes...
 

This is my code:

//______________________________________________________________________
_______


void Spi_init (void)
{
  int tmp;
  int err = 0;

  devspi = open ("/dev/syncser0", O_RDWR | O_SYNC);    
  if (devspi == -1)
    {
      fprintf (stderr, "\nError \n", strerror (errno));
      exit (1);
    }

  ioctl (devspi, SSP_MODE,       MASTER_BIDIR);        
  tmp = NORMAL_SYNC | WORD_SYNC | SYNC_ON | WORD_SIZE_24 | BIT_ORDER_MSB
| 
FLOW_CONTROL_DISABLE | CLOCK_NOT_GATED;
  if (ioctl(devspi, SSP_FRAME_SYNC, tmp)) {
    fprintf(stderr, "Couldn't change sync SSP_FRAME_SYNC\n");
    err++;
  }

  tmp = CLOCK_INEGEDGE | FRAME_NORMAL | STATUS_NORMAL;
  if (ioctl(devspi, SSP_IPOLARITY, tmp)) {
    fprintf(stderr, "Couldn't change polarity SSP_IPOLARITY\n");
    err++;
  }
  tmp = CLOCK_NORMAL | FRAME_INVERT | STATUS_NORMAL;
  if (ioctl(devspi, SSP_OPOLARITY, tmp)) {
    fprintf(stderr, "Couldn't change polarity SSP_OPOLARITY\n");
    err++;
  }

  /* 64 kHz, word_sync: 24 bits/sync, frame_sync: 1 (no framing) */  
  if (ioctl(devspi, SSP_SPEED, CODEC_VAL(FREQ_64kHz, 24, 1))) {
    fprintf(stderr, "Couldn't change sync SSP_SPEED\n");
  }

  /* 160 bytes (160 samples = 20 ms) buffering */
  if (ioctl(devspi, SSP_INBUFCHUNK, 160)) {
    fprintf(stderr, "Couldn't change sync SSP_BUFCHUNK\n");
    err++;
  }
}

//______________________________________________________________________
_______


int spi_write3(unsigned char *data)
{
   int nbytes_written;
   fprintf (stdout, "Trying to send 3 bytes... \n");
   nbytes_written = write(devspi, data, 3);
   fprintf (stdout, "3 bytes Written: %i, %i, %i \n", data[0], data[1],
data[2]);
   return nbytes_written;
}
int spi_read3(unsigned char *data)
{
   int nbytes_read;
   fprintf (stdout, "Trying to read 3 bytes... \n");
   nbytes_read = read(devspi, data, 3);
   fprintf (stdout, "3 bytes Read: %i, %i, %i \n", data[0], data[1],
data[2]);
   return nbytes_read;
}

//______________________________________________________________________
_______
//
// And finally this is my loop:
//______________________________________________________________________
_______


void loop (void)
{
  unsigned char outdata[3];
  unsigned char indata[3];

  outdata[0] = 0x03;
  outdata[1] = 0x0E;
  outdata[2] = 0;

 do {
  spi_write3(outdata);
  spi_read3(indata);
 } while(1);
}

//______________________________________________________________________
_______


Regards,
Carlos