// Transmit a MSG via UART
//-------------------------------
void scia_msg(char * msg)
{
	int i;
	i = 0;
	while(msg[i] != '\0')
	{
		scia_xmit(msg[i]);
		i++;
	}
}
void main(void)
{
    Uint16 SendChar;
    Uint16 ReceivedChar;

// Step 1. Initialize System Control registers, PLL, WatchDog, Clocks to default state:
// This function is found in the F2806x_SysCtrl.c file.
	InitSysCtrl();

	InitGpio(); //This function is found in the F2806x_Gpio.c file and illustrates how to set the GPIO to its default state.

// Step 2. Select GPIO for the device or for the specific application:
// This function is found in the F2806x_Gpio.c file.
// InitGpio(); skip this as this is example selects the I/O
// for SCI-A in this file itself
   InitSciGpio();

// Step 3. Initialize PIE vector table:
// The PIE vector table is initialized with pointers to shell Interrupt
// Service Routines (ISR).  The shell routines are found in F2806x_DefaultIsr.c.
// Insert user specific ISR code in the appropriate shell ISR routine in
// the DSP28_DefaultIsr.c file.
/*
// Disable and clear all CPU interrupts:
	DINT;
	IER = 0x0000;
	IFR = 0x0000;

      // Initialize Pie Control Registers To Default State:
      // This function is found in the F2806x_PieCtrl.c file.
	  // InitPieCtrl();  PIE is not used for this example

      // Initialize the PIE Vector Table To a Known State:
      // This function is found in F2806x_PieVect.c.
      // This function populates the PIE vector table with pointers
      // to the shell ISR functions found in F2806x_DefaultIsr.c.
	  InitPieVectTable();

      // Enable CPU and PIE interrupts
      // This example function is found in the F2806x_PieCtrl.c file.
      EnableInterrupts();
*/
// Step 4. Initialize all the Device Peripherals to a known state:
// This function is found in F2806x_InitPeripherals.c
// InitPeripherals(); skip this for SCI tests

// Step 5. User specific functions, Reassign vectors (optional), Enable Interrupts:

    LoopCount = 0;
    ErrorCount = 0;


    scia_fifo_init();	   // Initialize the SCI FIFO
    scia_loopback_init();  // Initalize SCI for digital loop back

    // Note: Autobaud lock is not required for this example

    // Send a character starting with 0
    SendChar = 0;

// Step 6. Send Characters forever starting with 0x00 and going through
// 0xFF.  After sending each, check the receive buffer for the correct value
/*
	for(;;)
    {
       scia_xmit(SendChar);
       while(SciaRegs.SCIFFRX.bit.RXFFST !=1) { } // wait for RRDY/RXFFST =1 for 1 data available in FIFO

       // Check received character
       ReceivedChar = SciaRegs.SCIRXBUF.all;
       if(ReceivedChar != SendChar) error();

       // Move to the next character and repeat the test
       SendChar++;
       // Limit the character to 8-bits
       SendChar &= 0x00FF;
       LoopCount++;
    }

*/
	int16 bits[8];
	char string[32];
	int conversionArray[256] = {
	-1, 56, 40, 55, 24, -1, 39, 52, 8, 57, -1, -1, 23, -1, 36, 13, 120, -1, 41,
	54, -1, -1, -1, 53, 7, -1, -1, -1, 20, 19, 125, 18, 104, 105, -1, -1, 25, 106, 38,
	-1, -1, 58, -1, -1, -1, -1, 37, 14, 119, 118, -1, -1, -1, 107, -1, -1, 4, -1, 3,
	-1, 109, 108, 2, 1, 88, -1, 89, -1, -1, -1, -1, 51, 9, 10, 90, -1, 22, 11, -1,
	12, -1, -1, 42, 43, -1, -1, -1, -1, -1, -1, -1, -1, 21, -1, 126, 127, 103, -1, 102,
	-1, -1, -1, -1, -1, -1, -1, 91, -1, -1, -1, -1, -1, 116, 117, -1, -1, 115, -1, -1,
	-1, 93, 94, 92, -1, 114, 95, 113, 0, 72, 71, -1, 68, 73, -1, -1, 29, -1, 70, -1,
	69, -1, -1, 35, 34, 121, -1, 122, -1, 74, -1, -1, 30, 6, -1, 123, -1, -1, -1, 124,
	17, -1, -1, -1, 67, 26, -1, 27, 28, -1, 59, -1, -1, -1, -1, -1, 15, -1, -1, -1,
	-1, -1, -1, -1, -1, 5, -1, -1, -1, 110, -1, 111, 16, 87, 84, -1, 45, 86, 85, -1,
	50, -1, -1, -1, 46, -1, -1, -1, 33, -1, 83, -1, 44, 75, -1, -1, 31, -1, -1, -1,
	-1, -1, -1, -1, 32, 100, 61, 101, 66, -1, 62, -1, 49, 99, 60, -1, 47, -1, -1, -1,
	48, 77, 82, 78, 65, 76, 63, -1, 64, 98, 81, 79, 80, 97, 96, 112};
	int i = 0;
	int index = 0;
	int mult = 1;
	while (1){
		bits[0] = GpioDataRegs.GPADAT.bit.GPIO8;
		bits[1] = GpioDataRegs.GPADAT.bit.GPIO9;
		bits[2] = GpioDataRegs.GPADAT.bit.GPIO10;
		bits[3] = GpioDataRegs.GPADAT.bit.GPIO11;
		bits[4] = GpioDataRegs.GPADAT.bit.GPIO12;
		bits[5] = GpioDataRegs.GPADAT.bit.GPIO13;
		bits[6] = GpioDataRegs.GPADAT.bit.GPIO14;
		bits[7] = GpioDataRegs.GPADAT.bit.GPIO15;

		index = 0;
		mult = 1;
		for(i=0;i<8;i++){
			index+=mult*bits[i];
			mult*=2;
		}
		int result = conversionArray[index];
		if (result == -1) {
			puts("ERROR! Check connections!");
		} else {
			sprintf(string, "%d", result);
			puts(string);

			for (i = 0; i < strlen(string); i++) {
				while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}//wait for current transmit to finish
				SendChar = (char)string[i];
				scia_xmit(SendChar);

				// Check received character
				ReceivedChar = SciaRegs.SCIRXBUF.all;
			}
			while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}//wait for current transmit to finish
			SendChar = (Uint16)10; // Send end of line character. (\n)
			scia_xmit(SendChar);
			while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}//wait for current transmit to finish
			SendChar = (Uint16)13; // Send end of carriage return character. (\r)
			scia_xmit(SendChar);
		}
	}
}
//
// Main
//
void main(void)
{
    Uint16 ReceivedChar;
    char *msg;

//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xS_SysCtrl.c file.
//
   InitSysCtrl();

//
// Step 2. Initialize GPIO:
// This example function is found in the F2837xS_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//
   InitGpio();

//
// For this example, only init the pins for the SCI-A port.
//  GPIO_SetupPinMux() - Sets the GPxMUX1/2 and GPyMUX1/2 register bits
//  GPIO_SetupPinOptions() - Sets the direction and configuration of the GPIOS
// These functions are found in the F2837xS_Gpio.c file.
//
   GPIO_SetupPinMux(28, GPIO_MUX_CPU1, 1);
   GPIO_SetupPinOptions(28, GPIO_INPUT, GPIO_PUSHPULL);
   GPIO_SetupPinMux(29, GPIO_MUX_CPU1, 1);
   GPIO_SetupPinOptions(29, GPIO_OUTPUT, GPIO_ASYNC);

//
// Step 3. Clear all __interrupts and initialize PIE vector table:
// Disable CPU __interrupts
//
   DINT;

//
// Initialize PIE control registers to their default state.
// The default state is all PIE __interrupts disabled and flags
// are cleared.
// This function is found in the F2837xS_PieCtrl.c file.
//
   InitPieCtrl();

//
// Disable CPU __interrupts and clear all CPU __interrupt flags:
//
   IER = 0x0000;
   IFR = 0x0000;

//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the __interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in F2837xS_DefaultIsr.c.
// This function is found in F2837xS_PieVect.c.
//
   InitPieVectTable();

//
// Step 4. User specific code:
//
   LoopCount = 0;

   scia_fifo_init();       // Initialize the SCI FIFO
   scia_echoback_init();   // Initialize SCI for echoback

   msg = "\r\n\n\nHello World!\0";
   scia_msg(msg);

   msg = "\r\nYou will enter a character, and the DSP will echo it back! \n\0";
   scia_msg(msg);

   for(;;)
   {
       msg = "\r\nEnter a character: \0";
       scia_msg(msg);

       //
       // Wait for inc character
       //
       while(SciaRegs.SCIFFRX.bit.RXFFST == 0) { } // wait for empty state

       //
       // Get character
       //
       ReceivedChar = SciaRegs.SCIRXBUF.all;

       //
       // Echo character back
       //
       msg = "  You sent: \0";
       scia_msg(msg);
       scia_xmit(ReceivedChar);

       LoopCount++;
   }
}
Example #4
0
void main(void)
{
    Uint16 SendChar;
    Uint16 ReceivedChar;
    
// Step 1. Initialize System Control registers, PLL, WatchDog, Clocks to default state:
        // This function is found in the DSP281x_SysCtrl.c file.
	InitSysCtrl();

// Step 2. Select GPIO for the device or for the specific application:
       // This function is found in the DSP281x_Gpio.c file.
       // InitGpio(); skip this as this is example selects the I/O for SCI in this file itself
    EALLOW;
    GpioMuxRegs.GPFMUX.all=0x0030;	// Select GPIOs to be Sci pins	 
                                    // Port F MUX - x000 0000 0011 0000
    EDIS;

// Step 3. Initialize PIE vector table:
      // The PIE vector table is initialized with pointers to shell Interrupt 
      // Service Routines (ISR).  The shell routines are found in DSP281x_DefaultIsr.c.
      // Insert user specific ISR code in the appropriate shell ISR routine in 
      // the DSP28_DefaultIsr.c file.

      // Disable and clear all CPU interrupts:
	DINT;
	IER = 0x0000;
	IFR = 0x0000;

      // Initialize Pie Control Registers To Default State:
      // This function is found in the DSP281x_PieCtrl.c file.
	  // InitPieCtrl();  PIE is not used for this example

      // Initialize the PIE Vector Table To a Known State:
      // This function is found in DSP281x_PieVect.c.
      // This function populates the PIE vector table with pointers
      // to the shell ISR functions found in DSP281x_DefaultIsr.c.
	  InitPieVectTable();  

      // Enable CPU and PIE interrupts
      // This example function is found in the DSP281x_PieCtrl.c file.   
      EnableInterrupts();
	
// Step 4. Initialize all the Device Peripherals to a known state:
      // This function is found in DSP281x_InitPeripherals.c
      // InitPeripherals(); skip this for SCI tests
	
// Step 5. User specific functions, Reassign vectors (optional), Enable Interrupts:

    LoopCount = 0;
    ErrorCount = 0;
    
    scia_fifo_init();	   // Initialize the SCI FIFO
    scia_loopback_init();  // Initalize SCI for digital loop back 

    // Note: Autobaud lock is not required for this example
    
    // Send a character starting with 0 
    SendChar = 0;								

// Step 6. Send Characters forever starting with 0x00 and going through
// 0xFF.  After sending each, check the recieve buffer for the correct value

	for(;;)
    { 
       scia_xmit(SendChar);
       while(SciaRegs.SCIFFRX.bit.RXFIFST !=1) { } // wait for XRDY =1 for empty state
  
       // Check received character
       ReceivedChar = SciaRegs.SCIRXBUF.all;			
       if(ReceivedChar != SendChar) error(1);

       // Move to the next character and repeat the test
       SendChar++;
       // Limit the character to 8-bits
       SendChar &= 0x00FF;
       LoopCount++;
    }

}