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.

tm4c123

I can receive data using UARTCharsAvail(UART0_BASE) inside a project wich include other pheriferics.

note I can sent data througth the uart but the function UARTCharsAvail(UART0_BASE) is not working.

I have test the uart conection with the lab 12 of the tivaware workshop. *(it works great,)

this is part of the code

while (seguro==1) //This is the main loop of the program
{

if ( UARTCharsAvail(UART0_BASE)) UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));

qeiPosition = QEIPositionGet(QEI0_BASE);
while(qeiPosition>100 & qeiPosition<10000 ){
qeiPosition = QEIPositionGet(QEI0_BASE);
qeiDirection = QEIDirectionGet(QEI0_BASE);
qeiVelocity=QEIVelocityGet(QEI0_BASE);

//UARTCharPut(UART0_BASE, '$');
//UARTCharPut(UART0_BASE, ',');
UART_OutUDec(qeiPosition);
UARTCharPut(UART0_BASE, ',');
if (qeiDirection<0) {UARTCharPut(UART0_BASE, '-');
}
//if (qeiDirection > 0) {UARTCharPut(UART0_BASE, '+');
//}
//UARTCharPut(UART0_BASE, ',');
UART_OutUDec(qeiVelocity);
//UARTCharPut(UART0_BASE, '@');
UARTCharPut(UART0_BASE, '\n');
UARTCharPut(UART0_BASE, '\r');


SysCtlDelay (1333333);//(Sec*100); // 1 msec=400periodos, mSec *100 = 0.1 sec
}//fin de while
//PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT | PWM_OUT_0_BIT, false);

seguro=0;
}
}

includes other periferial.

  • Buenos días Ruben,
    It is not clear on your post what your question is.
    Meanwhile, I can suggest that you treat your UART receiving code inside an interrupt, never inside a main while() loop. It gets more problematic if you check your UART Rx buffer only once every loop, and add a delay for every cycle - if you have many characters coming in, you will quickly loose received bytes that were not serviced during the delay.
    Check the interrupt examples of Tivaware and read some basics on interrupts, it will get your MCU to work much better.
    Saludos
    Bruno
  • Thanks for your respond bruno, the problem its presented in both cases using uart interrups or not . In my code I need to star a timer interrupt if I have received something trough the uart. So I put the timerEnable function inside a while loop (I tried inside a uart interrup with the same result [if I put the timer enable interrup inside the uart interrup handler]).
    note that the uart could send but not receive and the Timer enable function doesnt work

    while(true) //This is the main loop of the program
    {

    if ( UARTCharsAvail(UART0_BASE)) {UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));
    TimerEnable(TIMER0_BASE, TIMER_A);//this seem to be the problem
    }
    }


    I'm incluiding a reduced version of the code
    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_gpio.h"
    #include "inc/hw_types.h"
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/gpio.h"
    //#include "driverlib/qei.h"
    #include "driverlib/uart.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/timer.h"
    //#include "driverlib/pwm.h"
    //#include "serial.h"


    int main(void){

    uint32_t ui32Period;
    // Set the clocking to run directly from the crystal.//400/2*4=50mhz
    SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

    // configure uart
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 9600,
    (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
    UART_CONFIG_PAR_NONE));



    // configure timer interrurp
    ui32Period = (SysCtlClockGet() / 100) / 2; //100 hertz
    TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);
    IntEnable(INT_TIMER0A);
    TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    IntMasterEnable();

    while(true) //This is the main loop of the program
    {

    if ( UARTCharsAvail(UART0_BASE)) {UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));
    TimerEnable(TIMER0_BASE, TIMER_A);
    }
    }

    }


    void Timer0IntHandler(void) {
    // Clear the timer interrupt
    TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    // Read the current state of the GPIO pin and
    // write back the opposite state


    if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2))
    {
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
    }
    else
    {
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4);
    }
    }
  • Ruben,
    I suggest you split the different functionalities of your code to "mini-programs" until you get each working separately.
    Most of the fellows on this forum won't be able to check your code line by line - what I can assure to you is that the functions for timer and gpio int work perfectly, so it is something on the program structure - and the best way for you to find is to create your Frankenstein one limb at a time.
    Bruno