This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Sending 10.000 bits in 1 second



How can I write a program with interruption to send 10.000 bits in 1 second with manchester encoding? I'm using TIVA TM4C123G

  • Sorry for the slow response, but this question intrigued me so much I had to try it. In short, I used the SSI at twice the baud rate (20,000 bits/second) and send 16 bits for every 8 bits of data. I chose to use a lookup table (512 bytes of flash) to encode the data. I arbitrarily used rising edge for a 0 and falling edge for a 1, 0xFF for a start synchronization and 0x00 for end synchronization. This simple example did not use interrupts, but just sat polling so that it could stuff more data into the transmit FIFO as it became empty. It is imperative that you don't let the FIFO empty before the end of transmission. Lines 131 and 134 are commented out as it is not necessary to output the clock. However, you can uncomment these lines to see the relationship to the output data and the SSI clock.

    //*****************************************************************************
    //
    //SSI-Manchester.c - Simple example to transmit Manchester encoded data by SSI.
    //
    // Copyright (c) 2013-2017 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    // 
    // Texas Instruments (TI) is supplying this software for use solely and
    // exclusively on TI's microcontroller products. The software is owned by
    // TI and/or its suppliers, and is protected under applicable copyright
    // laws. You may not combine this software with "viral" open-source
    // software in order to form a larger program.
    // 
    // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
    // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
    // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
    // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
    // DAMAGES, FOR ANY REASON WHATSOEVER.
    // 
    //
    //*****************************************************************************
    
    #include <stdint.h>
    #include <stdbool.h>
    #include "tm4c1294ncpdt.h"
    #include "sysctl.h"
    #include "rom_map.h"
    #include "ssi.h"
    #include "pin_map.h"
    #include "hw_memmap.h"
    #include "gpio.h"
    
    #define MASTER SSI1_BASE
    
    
    void QSSIMasterInit(uint32_t SysClk_Freq, uint32_t baud_rate);
    void SSIPutManchester(int SSIBase, unsigned char character);
    
    //*****************************************************************************
    //
    //!
    //! A very simple example that sends a string out the SSI
    //! using Manchester encoding (0 - rising edge, 1 - falling edge)
    //
    //*****************************************************************************
    const uint16_t conversionTable[256] =
    {
    		0x5555, 0x5556, 0x5559, 0x555A, 0x5565, 0x5566, 0x5569, 0x556A,
    		0x5595, 0x5596, 0x5599, 0x559A, 0x55A5, 0x55A6, 0x55A9, 0x55AA,
    		0x5655, 0x5656, 0x5659, 0x565A, 0x5665, 0x5666, 0x5669, 0x566A,
    		0x5695, 0x5696, 0x5699, 0x569A, 0x56A5, 0x56A6, 0x56A9, 0x56AA,
    		0X5955, 0x5956, 0X5959, 0X595A, 0X5965, 0X5966, 0X5969, 0X596A,
    		0X5995, 0x5996, 0X5999, 0X599A, 0X59A5, 0X59A6, 0X59A9, 0X59AA,
    		0X5A55, 0x5A56, 0X5A59, 0X5A5A, 0X5A65, 0X5A66, 0X5A69, 0X5A6A,
    		0X5A95, 0x5A96, 0X5A99, 0X5A9A, 0X5AA5, 0X5AA6, 0X5AA9, 0X5AAA,
    		0X6555, 0x6556, 0X6559, 0X655A, 0X6565, 0X6566, 0X6569, 0X656A,
    		0X6595, 0x6596, 0X6599, 0X659A, 0X65A5, 0X65A6, 0X65A9, 0X65AA,
    		0X6655, 0x6656, 0X6659, 0X665A, 0X6665, 0X6666, 0X6669, 0X666A,
    		0X6695, 0x6696, 0X6699, 0X669A, 0X66A5, 0X66A6, 0X66A9, 0X66AA,
    		0X6955, 0x6956, 0X6959, 0X695A, 0X6965, 0X6966, 0X6969, 0X696A,
    		0X6995, 0x6996, 0X6999, 0X699A, 0X69A5, 0X69A6, 0X69A9, 0X69AA,
    		0X6A55, 0x6A56, 0X6A59, 0X6A5A, 0X6A65, 0X6A66, 0X6A69, 0X6A6A,
    		0X6A95, 0x6A96, 0X6A99, 0X6A9A, 0X6AA5, 0X6AA6, 0X6AA9, 0X6AAA,
    		0X9555, 0x9556, 0X9559, 0X955A, 0X9565, 0X9566, 0X9569, 0X956A,
    		0X9595, 0x9596, 0X9599, 0X959A, 0X95A5, 0X95A6, 0X95A9, 0X95AA,
    		0X9655, 0x9656, 0X9659, 0X965A, 0X9665, 0X9666, 0X9669, 0X966A,
    		0X9695, 0x9696, 0X9699, 0X969A, 0X96A5, 0X96A6, 0X96A9, 0X96AA,
    		0X9955, 0x9956, 0X9959, 0X995A, 0X9965, 0X9966, 0X9969, 0X996A,
    		0X9995, 0x9996, 0X9999, 0X999A, 0X99A5, 0X99A6, 0X99A9, 0X99AA,
    		0X9A55, 0x9A56, 0X9A59, 0X9A5A, 0X9A65, 0X9A66, 0X9A69, 0X9A6A,
    		0X9A95, 0x9A96, 0X9A99, 0X9A9A, 0X9AA5, 0X9AA6, 0X9AA9, 0X9AAA,
    		0XA555, 0xA556, 0XA559, 0XA55A, 0XA565, 0XA566, 0XA569, 0XA56A,
    		0XA595, 0xA596, 0XA599, 0XA59A, 0XA5A5, 0XA5A6, 0XA5A9, 0XA5AA,
    		0XA655, 0xA656, 0XA659, 0XA65A, 0XA665, 0XA666, 0XA669, 0XA66A,
    		0XA695, 0xA696, 0XA699, 0XA69A, 0XA6A5, 0XA6A6, 0XA6A9, 0XA6AA,
    		0XA955, 0xA956, 0XA959, 0XA95A, 0XA965, 0XA966, 0XA969, 0XA96A,
    		0XA995, 0xA996, 0XA999, 0XA99A, 0XA9A5, 0XA9A6, 0XA9A9, 0XA9AA,
    		0XAA55, 0xAA56, 0XAA59, 0XAA5A, 0XAA65, 0XAA66, 0XAA69, 0XAA6A,
    		0XAA95, 0xAA96, 0XAA99, 0XAA9A, 0XAAA5, 0XAAA6, 0XAAA9, 0XAAAA
    };
    
    const unsigned char myString[] = {"The quick brown fox jumped over the lazy dog\n\r\000"};
    
    int
    main(void)
    {
        uint32_t SysClk_Freq, baud_rate;
        const unsigned char *charPtr;
    
        SysCtlClockFreqSet(SYSCTL_OSC_INT, SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL );
        SysClk_Freq = SysCtlClockGet();
        baud_rate = 20000; // operate SSI at twice the Manchester encoded bit rate
    
        //
        // Enable the GPIO port that is used for the on-board LED.
        //
        SYSCTL_RCGCGPIO_R = SYSCTL_RCGCGPIO_R12;
    
    
        // Initialize SSI3 as BI master
        QSSIMasterInit(SysClk_Freq, baud_rate);
    
    	//
    	// Send data out master
    	//
    	charPtr = myString;
    	SSIPutManchester(MASTER, 0xFFu); //Start with sync frame
    	while (*charPtr != 0)
    	{
    		SSIPutManchester(MASTER, *charPtr);
    		charPtr++;
    	}
    	SSIPutManchester(MASTER, 0x00u); //End of frame
    
    }
    
    void SSIPutManchester(int SSIBase, unsigned char character)
    {
    	SSIDataPut(SSIBase, (conversionTable[character] ));
    }
    
    
    // Initialize SSI1 as master
    void QSSIMasterInit(uint32_t SysClk_Freq, uint32_t baud_rate)
    {
    	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI1);
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    
    //    MAP_GPIOPinConfigure(GPIO_PB5_SSI1CLK);
        MAP_GPIOPinConfigure(GPIO_PE4_SSI1XDAT0);
    
    //    MAP_GPIOPinTypeSSI(GPIO_PORTB_AHB_BASE, GPIO_PIN_5);
        MAP_GPIOPinTypeSSI(GPIO_PORTE_AHB_BASE, GPIO_PIN_4 );
    
        MAP_SSIConfigSetExpClk(MASTER, SysClk_Freq, SSI_FRF_MOTO_MODE_1, SSI_MODE_MASTER, baud_rate, 16);
        MAP_SSIEnable(MASTER);
        SSIAdvModeSet(MASTER, SSI_ADV_MODE_LEGACY);
    }