Author Topic: TM4C123GH6PM UART problem [SOLVED]  (Read 12148 times)

0 Members and 1 Guest are viewing this topic.

Offline Aodhan145Topic starter

  • Frequent Contributor
  • **
  • Posts: 404
  • Country: 00
TM4C123GH6PM UART problem [SOLVED]
« on: August 17, 2016, 08:26:00 pm »
I am making the step up from 8 bit to 32 bit and it is hell.
I decided to sit down for an hour or two each day for the rest of the summer and try to learn how to do something different. Today I decided to do a bit of UART. I went through the data sheet steps on how to set up the UART but I am having problems. I am using the TM4C123GXL launch pad with ti's ccs. The problem with my code is It doesn't seem to transmit. It only receives, I know that as the LEDs go off but I am not receiving any characters back I have spent a few hours trying to realize why and I am still clueless. I would be grateful for any help that is offered.
Code: [Select]
#include <stdio.h>
#include <stdint.h>
#include "inc/tm4c123gh6pm.h"

void printChar(char);
char readChar(void);

int main(void){
//UART 2 = RX PD6 TX PD7
//Run Mode Clock Gating to UART 2
SYSCTL_RCGC1_R |= (1<<2);
//Clock gating to GPIO
SYSCTL_RCGC2_R |= (1<<3);
//Enable and provide clock in run mode to UART module 2
SYSCTL_RCGCUART_R |= (1<<2);
//GPIO Enable clock to Port D
SYSCTL_RCGCGPIO_R |= (1<<3);
//Disable UART2
UART2_CTL_R &= ~(1<<0);
//Set Baud-Rate Divisor
//(Integer Part)
UART2_IBRD_R = 0x8;
//Decimal part
UART2_FBRD_R = 0x2C;
//Set UART 2 parameters
UART2_LCRH_R |= ((1<<6)|(1<<5)|(1<<4)); //Word Length 8 bits 1 stop
//Enable UART2
UART2_CTL_R |= (1<<0)|(1<<8)|(1<<9);
//GPIO Enable Alternate Function (UART)
GPIO_PORTD_AFSEL_R |= (1<<6)|(1<<7);
//GPIO Enable Digital
GPIO_PORTD_DEN_R |= (1<<6)|(1<<7);
//GPIO Port Mux Enable UART2 Peripherial for PD6 PD7
GPIO_PORTD_PCTL_R |= (1<<24)|(1<<28);
//Disable Analog
GPIO_PORTD_AMSEL_R &= ~((1<<6)|(1<<7));

// Configure LED pins
    SYSCTL_RCGCGPIO_R |= (1<<5); // enable clock on PortF
    GPIO_PORTF_DIR_R = (1<<1)|(1<<2)|(1<<3);  // make LED pins (PF1, PF2, and PF3) outputs
    GPIO_PORTF_DEN_R = (1<<1)|(1<<2)|(1<<3); // enable digital function on LED pins
    GPIO_PORTF_DATA_R = ((1<<1)|(1<<2)|(1<<3));

readChar();
printChar('G');
return 0;
}

char readChar(void)
{
    char c;
    while((UART2_FR_R & (1<<4)) != 0);
    c = UART2_DR_R;
    if(c=='A'){
        GPIO_PORTF_DATA_R &= ~((1<<1)|(1<<2)|(1<<3));
    }
    return c;
}

void printChar(char c)
{
    while((UART2_FR_R & (1<<5)) != 0);
    UART2_DR_R = c;
}
« Last Edit: December 29, 2017, 01:26:43 am by Aodhan145 »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: TM4C123GH6PM UART problem
« Reply #1 on: August 17, 2016, 09:30:54 pm »
Use one of thebuart examples and go through the source code to the flow of code and how they acted on the registers.
================================
https://dannyelectronics.wordpress.com/
 

Offline rsjsouza

  • Super Contributor
  • ***
  • Posts: 6200
  • Country: us
  • Eternally curious
    • Vbe - vídeo blog eletrônico
Re: TM4C123GH6PM UART problem
« Reply #2 on: August 17, 2016, 09:42:46 pm »
I haven't tried to set up UART comms on TM4C123 using direct register accesses, thus I can't help you in this particular regard. However, I just wanted to let you know the examples in their software package (Tivaware) have ROM coded libraries that end up saving you flash memory. I haven't had any problems with their UART initialization routines, although a few other bugs had crept in.
Vbe - vídeo blog eletrônico http://videos.vbeletronico.com

Oh, the "whys" of the datasheets... The information is there not to be an axiomatic truth, but instead each speck of data must be slowly inhaled while carefully performing a deep search inside oneself to find the true metaphysical sense...
 

Offline Aodhan145Topic starter

  • Frequent Contributor
  • **
  • Posts: 404
  • Country: 00
Re: TM4C123GH6PM UART problem
« Reply #3 on: August 17, 2016, 10:41:22 pm »
Use one of thebuart examples and go through the source code to the flow of code and how they acted on the registers.

I have and I think that they are identical starting to really piss me off.
 

Offline Aodhan145Topic starter

  • Frequent Contributor
  • **
  • Posts: 404
  • Country: 00
Re: TM4C123GH6PM UART problem
« Reply #4 on: August 17, 2016, 10:43:11 pm »
I haven't tried to set up UART comms on TM4C123 using direct register accesses, thus I can't help you in this particular regard. However, I just wanted to let you know the examples in their software package (Tivaware) have ROM coded libraries that end up saving you flash memory. I haven't had any problems with their UART initialization routines, although a few other bugs had crept in.



Thanks for showing that ill remember it for the future if I have any problems with the tivaware functions. I've done everything with just the registers here. I haven't started using them yet.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: TM4C123GH6PM UART problem
« Reply #5 on: August 17, 2016, 10:49:06 pm »
'they are identical starting to really piss me off.'

You have lots of empirical evidence suggesting otherwise.
================================
https://dannyelectronics.wordpress.com/
 

Offline Aodhan145Topic starter

  • Frequent Contributor
  • **
  • Posts: 404
  • Country: 00
Re: TM4C123GH6PM UART problem
« Reply #6 on: August 17, 2016, 10:57:09 pm »
'they are identical starting to really piss me off.'

You have lots of empirical evidence suggesting otherwise.
Please show I have tried like 50 sites and changed them each time as each site was slightly different in the order none worked. It is just the transmit that doesn't work it does receive.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: TM4C123GH6PM UART problem
« Reply #7 on: August 17, 2016, 11:01:06 pm »
Easy.

You take a working sample code from ti. You identify every relevant function calls. You expand its source code. You find out how those calls impact which registers. You then replicate that in your code.

Done.
================================
https://dannyelectronics.wordpress.com/
 

Offline Aodhan145Topic starter

  • Frequent Contributor
  • **
  • Posts: 404
  • Country: 00
Re: TM4C123GH6PM UART problem
« Reply #8 on: August 18, 2016, 12:07:04 am »
I got UART0 working but UART2 wont work with the same code. I think there are some registers set by default for UART0 but not UART2 so that might be preventing my code from working. I will look in to it another time.
 

Offline Aodhan145Topic starter

  • Frequent Contributor
  • **
  • Posts: 404
  • Country: 00
Re: TM4C123GH6PM UART problem
« Reply #9 on: August 18, 2016, 11:49:24 pm »
PROBLEM SOLVED  :-+

The problem was I picked a UART at random and chose 2. The tx pin for UART2 (PD7) is protected and needs unlocked before use. That is why it could receive but not transmit and that is why my code was identical to all the UART tutorials on the internet but would not work.
 

Offline K5HJ

  • Regular Contributor
  • *
  • Posts: 60
  • Country: us
Re: TM4C123GH6PM UART problem [SOLVED]
« Reply #10 on: August 19, 2016, 03:38:16 am »
You're not the first one to do this.  I've been writing code for these processors for at least 4 years and I still get caught in this trap sometimes.
The data sheet should have a caveat in big red letters on page one." Any pin that can be assigned to NMI must be unlocked before use."

The registers do look a bit daunting but it is a very capable device and well worth the time spent learning.

Randy
 
The following users thanked this post: Aodhan145

Offline Aodhan145Topic starter

  • Frequent Contributor
  • **
  • Posts: 404
  • Country: 00
Re: TM4C123GH6PM UART problem [SOLVED]
« Reply #11 on: August 19, 2016, 12:05:05 pm »
You're not the first one to do this.  I've been writing code for these processors for at least 4 years and I still get caught in this trap sometimes.
The data sheet should have a caveat in big red letters on page one." Any pin that can be assigned to NMI must be unlocked before use."

The registers do look a bit daunting but it is a very capable device and well worth the time spent learning.

Randy

I have to say I don't like the data sheet for the processor. I prefer the atmel 8 bit ones I am used to but this is a lot more complicated so I expect the datasheet to be a bit like that.
I wasted about 6 hrs on that NMI pin I was copying tutorials from everywhere but none would work for UART2.

I have decided to put a bit of time in to learning this so hopefully it is worthwhile. How do the other Ti arm cortex parts compare? Is coding them much the same?
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: TM4C123GH6PM UART problem [SOLVED]
« Reply #12 on: August 19, 2016, 02:05:58 pm »
Many chips have similar features to assign multiple functions to a limited number of pins.

The pin remapping feature on the PIC24F is the best in that regard.
================================
https://dannyelectronics.wordpress.com/
 

Offline Aodhan145Topic starter

  • Frequent Contributor
  • **
  • Posts: 404
  • Country: 00
Re: TM4C123GH6PM UART problem [SOLVED]
« Reply #13 on: August 19, 2016, 02:09:31 pm »
Many chips have similar features to assign multiple functions to a limited number of pins.

The pin remapping feature on the PIC24F is the best in that regard.

I am still learning, I accidentally just reassigned a JTAG pin to be a UART and was wondering why my board wouldn't reprogram.  :palm: I have fixed it using a tool from ti's website. I'm not going to make that mistake again.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: TM4C123GH6PM UART problem [SOLVED]
« Reply #14 on: August 19, 2016, 02:18:48 pm »
you aren't along there.

Here is a tip that I learned on Luminary chips and I have been using it pretty much anything I do: insert a delay loop as the first thing to do in the user space. It gives the debugger time before it is kicked out by your code.

It has save me lots of time, :)
================================
https://dannyelectronics.wordpress.com/
 
The following users thanked this post: Aodhan145

Offline Aodhan145Topic starter

  • Frequent Contributor
  • **
  • Posts: 404
  • Country: 00
Re: TM4C123GH6PM UART problem [SOLVED]
« Reply #15 on: August 19, 2016, 02:19:56 pm »
you aren't along there.

Here is a tip that I learned on Luminary chips and I have been using it pretty much anything I do: insert a delay loop as the first thing to do in the user space. It gives the debugger time before it is kicked out by your code.

It has save me lots of time, :)

That is an ingenious idea. Thanks I will do it in the future.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: TM4C123GH6PM UART problem [SOLVED]
« Reply #16 on: August 19, 2016, 02:32:20 pm »
Don't thank me: thank Luminary and their "wonderful" chips, :)

They actually mentioned that in the datasheets.
================================
https://dannyelectronics.wordpress.com/
 

Offline Aodhan145Topic starter

  • Frequent Contributor
  • **
  • Posts: 404
  • Country: 00
Re: TM4C123GH6PM UART problem [SOLVED]
« Reply #17 on: August 19, 2016, 02:45:54 pm »
Don't thank me: thank Luminary and their "wonderful" chips, :)

They actually mentioned that in the datasheets.

I never knew that TI had bought those chips. I suppose that explains the whole lm4f120 and TM4C1233H6PM situation.
 

Offline K5HJ

  • Regular Contributor
  • *
  • Posts: 60
  • Country: us
Re: TM4C123GH6PM UART problem [SOLVED]
« Reply #18 on: August 19, 2016, 05:30:02 pm »
You're not the first one to do this.  I've been writing code for these processors for at least 4 years and I still get caught in this trap sometimes.
The data sheet should have a caveat in big red letters on page one." Any pin that can be assigned to NMI must be unlocked before use."

The registers do look a bit daunting but it is a very capable device and well worth the time spent learning.

Randy

I have to say I don't like the data sheet for the processor. I prefer the atmel 8 bit ones I am used to but this is a lot more complicated so I expect the datasheet to be a bit like that.
I wasted about 6 hrs on that NMI pin I was copying tutorials from everywhere but none would work for UART2.

I have decided to put a bit of time in to learning this so hopefully it is worthwhile. How do the other Ti arm cortex parts compare? Is coding them much the same?

The TM4C123 and TM4C 129 parts are very similar. I have programmed both. 
I have grown fond of Code Composer Studio after getting used to the Eclipse interface. And the free license is nice.
My (ex)company also used the Sitara family of parts and the CCS tools are the same.
Using TivaWare and AM335x StarterWare has been a big help. Although some of the code is buggy, it still has been useful.
Welcome the ARM.

Randy
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: TM4C123GH6PM UART problem [SOLVED]
« Reply #19 on: August 19, 2016, 07:28:26 pm »
The Luminary chips are quite complicated and having Stellaris / Tivaware help getting up the learning curve.

The MSP432 is an interesting chip for its blend of performance and low-power consumption. Too bad TI has yet to fix the compiler to allow a more seamless transition between 430 and 432 code.
================================
https://dannyelectronics.wordpress.com/
 

Offline Aodhan145Topic starter

  • Frequent Contributor
  • **
  • Posts: 404
  • Country: 00
Re: TM4C123GH6PM UART problem [SOLVED]
« Reply #20 on: August 19, 2016, 09:10:20 pm »
The Luminary chips are quite complicated and having Stellaris / Tivaware help getting up the learning curve.

The MSP432 is an interesting chip for its blend of performance and low-power consumption. Too bad TI has yet to fix the compiler to allow a more seamless transition between 430 and 432 code.

This is my first experience with ti micros. I need to pick up a couple of MSP430s. I have only ever used a lot of Atmel ones and one PIC16. I got into electronics when I picked up an arduino a few years ago when I thought it was amazing that i could turn on an LED over the internet. So thats why i'm a bit of an atmel fanboy.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: TM4C123GH6PM UART problem [SOLVED]
« Reply #21 on: August 19, 2016, 09:47:00 pm »
then you may want to check out msp432: it is essentially a 32-bit msp430, with (mostly) compatible peripherals.

Check out the porting guide before you jump in, however.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: TM4C123GH6PM UART problem [SOLVED]
« Reply #22 on: August 19, 2016, 10:28:39 pm »
Updated my compiler to 15.12 LTS and the interrupts worked beautifully - as I had used the same vector names so my code compiled and ran as expected.

I'm a happy camper.

BTW: TI should have updated the porting guide.
================================
https://dannyelectronics.wordpress.com/
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->