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.

First Steps with Stellaris



Hello,

i make my first Speps with Stellars now and want to set up a simple UART Programm, which sends one Character to my PC
I use a kind of the Exampleprogramm from here:

http://www.ti.com/lit/ug/spmu019o/spmu019o.pdf 

And tit looks like this:

#include "inc/hw_gpio.h"
#include "inc/hw_memmap.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom_map.h"


void main(void)
{
// 50 MHz Takt - 16MHz Quarz + PLL
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);

UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 19200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
UARTEnable(UART1_BASE);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Port F als GPIO aktivieren
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_4); // GPIO 4 als Output

while(1)
{
UARTCharPut(UART1_BASE, 'c');
SysCtlDelay(2000000);
}
}

but there is no communication to my PC.
My Hardware is the Stellaris Launchpad and i want to connect the Pin B1 with Rx of an FT232.
Why?

Thank you!
Daniel 

  • Hi,

    To get your UART1 working you need to follow some mandatory configuration steps - just read carefully the uart-echo example in your board documentation and adapt these steps to UART1. The first step is to enable the clock for UART1 with a call to SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1), since this is not enabled by default as UART0.

    Petrei

  • The PinMux utility suggests the following steps to enable the UART1 output:

        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
        GPIOPinConfigure(GPIO_PB1_U1TX);
        GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_1);

    Regards,

    István

  • Hello,

    thank you two for the answers.

    When i want to use this Command:

    GPIOPinConfigure(GPIO_PB1_U1TX);

    CCS displays an Error if i Compile the Programm. It displays the Message "GPIO_PB1_U1TX is undeffined".

    But i don´t understand this. Why i can´t use him for Transmitting? I take a look into the Manual:

    https://dl-web.dropbox.com/get/Stellaris/Manual.pdf?w=9c14f238

    And on Page 11 they write that PB1 has the alternative function U1TX.



  • Hi,

    The undefined symbol is defined in pin_map.h file, but you need also to pre-define the microcontroller used, like in this picture:

    Petrei

  • Hey,

    thank you for this Tipp, but i don´t have this Window.

    Edit: 

    Have found it. With active advanced settings i see it ;) 

    A second Edit:

    It looks like the UART sending something. I don´t get any Message on my PC, but my Oscilloscope detect something.

    Thank you very much for your help :) 

    A last question....

    Did i repeat the steps with the Predefining of my µC in every new Project or is it global for all Projects?

  • Daniel Kampert said:
    Did i repeat the steps with the Predefining of my µC in every new Project or is it global for all Projects?

    Each project needs to define its own settings.

    If you don't want to have to do it "manually" each time, then just base your new project on an existing one which has the required settings...

  • Hey,

    thank you for the Answer.

    Now i try to config the Chip as an I²C Slave to connect him with my Raspberry Pi.

    I use this Code:

    void I2cInit( void )
    {
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
        
        GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);
        
        I2CSlaveIntEnable(I2C0_SLAVE_BASE);
        I2CIntRegister(I2C0_SLAVE_BASE, vI2cIntHandler);  

        I2CSlaveInit(I2C0_SLAVE_BASE,SlaveAdr);

    }

    And this is my Code:

    /* Include of StellarisWare */
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "driverlib/rom.h"
    #include "driverlib/i2c.h"

    /* Include of standard C Headerfiles */
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    #define SLAVE_ADDRESS 0x3C

    //******************************************************************************//
    // //
    // The error routine that is called if the driver library encounters an error. //
    // //
    //******************************************************************************//
    #ifdef DEBUG
    void
    __error__(char *pcFilename, unsigned long ulLine)
    {
    }
    #endif

    //******************************************************************************//
    // //
    // Subroutines //
    // //
    //******************************************************************************//

    void Send_UART(char Data[])
    {
    int n; // Local Variable for the Counter
    size_t Laenge; // Local Variable for the Stringlenght

    Laenge = strlen(Data); // Get Lenght of target String
    for(n = 0; n < Laenge; n++)
    {
    UARTCharPut(UART1_BASE, Data[n]); // Print each Character of the target String
    }

    UARTCharPut(UART1_BASE, 0x0A); // Send LF
    UARTCharPut(UART1_BASE, 0x0D); // Send CR
    }

    void I2C_SlaveInit(void)
    {
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // Enable Port E (for I²C)
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2); // Enable I²C2-Module

    GPIOPinConfigure(GPIO_PE4_I2C2SCL); // Config alternative SCL Function on PortE4
    GPIOPinConfigure(GPIO_PE5_I2C2SDA); // Config alternative SDA Function on PortE5
    GPIOPinTypeI2C(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5); // Config PortE4 & 5 for I²C

    /* I²C Configuration */
    I2CSlaveEnable(I2C2_SLAVE_BASE);
    I2CSlaveInit(I2C2_SLAVE_BASE, SLAVE_ADDRESS);

    }

    //******************************************************************************//

    void main(void)
    {
    /* Variables */
    char String[10];

    /* System Configuration */
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_XTAL_16MHZ | // 16 MHz Clock
    SYSCTL_OSC_MAIN);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable Port F (for RGB LED)
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // Enable Port B (for UART)
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); // Enable UART1-Module

    /* Port Configuration */
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3); // Set Pin 3 of PortF as an Output
    GPIOPinConfigure(GPIO_PB1_U1TX); // Config PortB1 as Tx
    GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_1); // Config alternative UART Function of PortB1

    /* UART1 Configuration */
    UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 19200, // Config UART1 to 19200 Baud,
    (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | // 8-Bit, 1 Stopbit,
    UART_CONFIG_PAR_NONE)); // no Parity
    UARTEnable(UART1_BASE); // Enable UART1

    /* Print out Clock */
    ltoa(SysCtlClockGet(), String); // Convert Returnvalue of SysCtlClockGet() into a String
    Send_UART("Systemclock:");
    Send_UART(String); // Send String

    I2C_SlaveInit();

    while(1)
    {
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 8); // Set Pin 3 to High Level
    SysCtlDelay(SysCtlClockGet() / 10 / 3); // Delay of 3 Cycles/loop
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0); // Set Pin 3 to Low Level
    SysCtlDelay(SysCtlClockGet() / 10 / 3); // Delay of 3 Cycles/loop
    }
    }

    I want use I2C2. 

    The Board is connected with an DS1307 RTC over I²C to my Raspberry Pi.

    But when i want display the Devices at the Bus the Raspberry shows no Device. When the Chip is disconnected, it shows the RTC and it works very well.

    Where is my misstake?

    Thanks and greetings 

    Daniel