Switches and LEDs on the ADSP-CM408F EZ-KIT Lite Board from 'No Boot - idle' mode

by Crossware 26. August 2014 18:32

We like examples to be as simple as possible and this is as simple as we can make it for controlling both the switches and the LEDs on the ADSP-CM408F EZ-KIT Lite Board.

The switches SW4 and SW5 are disabled by default and so from a 'No Boot - idle' mode, the soft switches must be configured.  This means sending commands to the U40 chip using the TWI interface.

The TWI clock and data pins are not multiplexed and so there is no need to configure the GPIO in order to use them.

Possibly we could get away with fewer while loops in the code below and we could also run the TWI at a faster speed.  But it works as written and that should get you started.

Pressing SW4 turns on LED1 and turns off LED2.  Pressing SW5 turns on LED3 and turns off LED4.

 

#include "xstdsys.h"

#define DELAY 100000

#define LED1PIN 7
#define LED2PIN 6
#define LED3PIN 5
#define LED4PIN 9

#define SW4PIN 10
#define SW5PIN 8

main()
{
    g_pTWI0->CLKDIV = 0XFFFF;
    g_pTWI0->MSTRADDR = 0X0020;    // U40
    g_pTWI0->CTL = TWI_CTL_EN;

    // set register 13 (gpiob) U40 to 0X3E
    // register 1 (iodirb) defaults to 0XFF and so need not be configured
    g_pTWI0->MSTRCTL &= ~(TWI_MSTRCTL_DCNT0 | TWI_MSTRCTL_DCNT1 | TWI_MSTRCTL_DCNT2 | TWI_MSTRCTL_DCNT3 | TWI_MSTRCTL_DCNT4 | TWI_MSTRCTL_DCNT5 | TWI_MSTRCTL_DCNT6 | TWI_MSTRCTL_DCNT7);
    g_pTWI0->MSTRCTL |= 0X02 << 6;    // transmit 2 bytes
    g_pTWI0->TXDATA8 = 0X13;    // GPIOB
    g_pTWI0->MSTRCTL |= TWI_MSTRCTL_EN;
    while (g_pTWI0->FIFOSTAT & (TWI_FIFOSTAT_TXSTAT0 | TWI_FIFOSTAT_TXSTAT1));
    while ((g_pTWI0->ISTAT & TWI_ISTAT_TXSERV) == 0);
    g_pTWI0->ISTAT = TWI_ISTAT_TXSERV;
    g_pTWI0->TXDATA8 = 0X3E;     // leds and switches enabled
    while ((g_pTWI0->ISTAT & TWI_ISTAT_MCOMP) == 0);
    g_pTWI0->ISTAT = TWI_ISTAT_TXSERV | TWI_ISTAT_MCOMP;


    g_pPORTF->INEN_SET = 1 << SW4PIN;    // enable input
    g_pPORTE->INEN_SET = 1 << SW5PIN;    // enable input
    g_pPORTE->DIR_SET = 1 << LED1PIN;     // set as output
    g_pPORTE->DIR_SET = 1 << LED2PIN;     // set as output
    g_pPORTE->DIR_SET = 1 << LED3PIN;     // set as output
    g_pPORTE->DIR_SET = 1 << LED4PIN;     // set as output

    while (1)                   
    {
        if (g_pPORTF->DATA & (1 << SW4PIN))
        {
            g_pPORTE->DATA_SET = 1 << LED1PIN;
            g_pPORTE->DATA_CLR = 1 << LED2PIN;
        }
        else
        {
            g_pPORTE->DATA_CLR = 1 << LED1PIN;
            g_pPORTE->DATA_SET = 1 << LED2PIN;
        }
        if (g_pPORTE->DATA & (1 << SW5PIN))
        {
            g_pPORTE->DATA_SET = 1 << LED3PIN;
            g_pPORTE->DATA_CLR = 1 << LED4PIN;
        }   
        else
        {
            g_pPORTE->DATA_CLR = 1 << LED3PIN;
            g_pPORTE->DATA_SET = 1 << LED4PIN;
        }
    }
}

Tags: , ,

Blog

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About this blog

This is where you will find topical information that we think might be useful to you.

Month List