AnsweredAssumed Answered

K60 SPI no CLK signal

Question asked by Daniel Chai on Jun 24, 2013
Latest reply on Jul 2, 2013 by Daniel Chai

Hi All,

 

Now I am trying to use the SPI communication on TWR-K60N512 board to control the a DOGS-102-6 LCD.

I edited the SPI sample code under /mqx/example/spi, and connected elevator board signal to the LCD through:

(SPI2)

Elevator board                    LCD

Pin 7 on J6                       CLK

Pin 9 on J6                       CS

Pin 10 on J6                      MOSI

Now the problem is that there is not clock signal and data signal from Pin7 and Pin9.

 

The code is as following:

spifd = fopen ("spi2:" NULL);

if (NULL == spifd)

{

    printf ("Error opening SPI driver!\n");

      _time_delay (200L);

      _task_block ();

}


   /* Display baud rate */
   printf ("Current baud rate ... ");
   if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_GET_BAUD, &param))
   {
      printf ("%d Hz\n", param);
   } else {
      printf ("ERROR\n");
   }

   /* Set a different rate */
   param = 500000;
   printf ("Changing the baud rate to %d Hz ... ", param);
   if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_SET_BAUD, &param))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }

   /* Display baud rate */
   printf ("Current baud rate ... ");
   if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_GET_BAUD, &param))
   {
      printf ("%d Hz\n", param);
   } else {
      printf ("ERROR\n");
   }

   /* Set clock mode */
   param = SPI_CLK_POL_PHA_MODE0;
   printf ("Setting clock mode to %s ... ", clock_mode[param]);
   if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_SET_MODE, &param))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }

   /* Get clock mode */
   printf ("Getting clock mode ... ");
   if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_GET_MODE, &param))
   {
      printf ("%s\n", clock_mode[param]);
   } else {
      printf ("ERROR\n");
   }

   /* Set big endian */
   param = SPI_DEVICE_BIG_ENDIAN;
   printf ("Setting endian to %s ... ", param == SPI_DEVICE_BIG_ENDIAN ? "SPI_DEVICE_BIG_ENDIAN" : "SPI_DEVICE_LITTLE_ENDIAN");
   if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_SET_ENDIAN, &param))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }

   /* Get endian */
   printf ("Getting endian ... ");
   if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_GET_ENDIAN, &param))
   {
      printf ("%s\n", param == SPI_DEVICE_BIG_ENDIAN ? "SPI_DEVICE_BIG_ENDIAN" : "SPI_DEVICE_LITTLE_ENDIAN");
   } else {
      printf ("ERROR\n");
   }

   /* Set transfer mode */
   param = SPI_DEVICE_MASTER_MODE;
   printf ("Setting transfer mode to %s ... ", device_mode[param]);
   if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_SET_TRANSFER_MODE, &param))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }

   /* Get transfer mode */
   printf ("Getting transfer mode ... ");
   if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_GET_TRANSFER_MODE, &param))
   {
      printf ("%s\n", device_mode[param]);
   } else {
      printf ("ERROR\n");
   }

   /* Clear statistics */
   printf ("Clearing statistics ... ");
   if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_CLEAR_STATS, NULL))
   {
      printf ("OK\n");
   } else {
      printf ("ERROR\n");
   }

   /* Get statistics */
   printf ("Getting statistics:\n");
   if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_GET_STATS, &stats))
   {
      printf ("Interrupts:   %d\n", stats.INTERRUPTS);
      printf ("Rx packets:   %d\n", stats.RX_PACKETS);
      printf ("Rx overflow:  %d\n", stats.RX_OVERFLOWS);
      printf ("Tx packets:   %d\n", stats.TX_PACKETS);
      printf ("Tx aborts :   %d\n", stats.TX_ABORTS);
      printf ("Tx underflow: %d\n", stats.TX_UNDERFLOWS);
   } else {
      printf ("ERROR\n");
   }

     /* Write a byte*/

     send_buffer[0] = 0x40;
  
      /* Write instruction */

     do{
          result = fwrite (send_buffer, 1, 1, spifd);

     }while( result < 1);

     fflush (spifd);

 

 

Thank you.

Outcomes