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

SPI





Hi,


> Did you change the CODEC_VAl parameters to reflect the
> 24 bits/sync, e.g: ?
>    /* 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");
>    }
> Make sure you read as much as you write, if that has something to do 
> with it. Perhaps somethings goes wrong if the receiver gets overrun.


Yes, I changed CODEC_VAL and I read as much as I write. 
I don't know what I am doing wrong.
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_write (int byte): 
//______________________________________________________________________
_______


int Spi_write (int byte)
{ 
  int nbytes_written;
  int pointer_byte [1];


  nbytes_written = read (devspi, pointer_byte, 1);       // DUMMY READ
  if (nbytes_written == -1)
    {
      fprintf (stderr, "\nError %s\n", strerror (errno));
    }
  else
    {
      fprintf (stdout, "Read: %X \n", pointer_byte [0]);
    }
  pointer_byte [0] = byte;


  nbytes_written = write (devspi, pointer_byte, 1);      
  debug_writes ++;
  fprintf (stdout, " %i \n", debug_writes);
  return (nbytes_written);
}



And finally this is my loop:
do
{
  Spi_write (0x03);        // READ command
  Spi_write (0x0E);        // Register
  Spi_write (0x00);        // Third write
} while (1);



I get this output:
Read: 812FF
 1
Read: FF
 2
Read: FF


And then program blocks in the third write. I don't know why...
Thank you very much for your help. I really appreciate it.

Regards,
Carlos