Jump to content
43oh

debugging UART communications


Recommended Posts

https://gist.github.com/chemuduguntar/4752294

 

hi all,

 

I am trying to write a simple demo that streams pi over serial port continuously,

 

I have initialised the serial port to 9600 baud, enable transmit interrupt and send the first character. I've setup so that when the character in the buffer has finished transmitting, another character (the next digit in pi) will be written to the transmit buffer.

 

However all I get is '3' being transmitted and nothing else, what am I doing wrong?

 

I was wondering about whether it had something to do with hardware flow control, i.e. if there is no receiver or the receiver isn't setup correctly it will not send any characters, is this the case? do I have hardware flow control enabled, if so how can I turn it off?

Link to post
Share on other sites

you are only sending 1 char, you need to refill the TX buffer after the first char is transmitted.

 

I noticed I have the transmit_char commented out inside the interrupt handler. I also turn off the leds in that interrupt handler, so even if it just sent one the interrupt should be set - it's like the interrupt handler isn't set up right or is not masked in...

Link to post
Share on other sites

If I change the transmit_char function send the characters in a loop, then it is working, I get pi:

 

void transmit_char() {
    while (1) {
        UCA0TXBUF = pi[pos];
        pos++;
        if (pi[pos] == '\0') pos = 0;

        while (! (UCA0TXIFG & IFG2));
    }
}

 

Just the interrupt that is not setup properly now.

Link to post
Share on other sites

Found the problem, starting the UART unit seems to clear the interrupt enable register; solution is to set enable interrupts after.

 

    UCA0CTL1 &= ~(UCSWRST);

    IE2      |= UCA0TXIE;

 

It even says it in the manual:

 

The recommended USCI initialization/re-configuration process is:
1. Set UCSWRST (BIS.B #UCSWRST,&UCAxCTL1)
2. Initialize all USCI registers with UCSWRST = 1 (including UCAxCTL1)
3. Configure ports.
4. Clear UCSWRST via software (BIC.B #UCSWRST,&UCAxCTL1)
5. Enable interrupts (optional) via UCAxRXIE and/or UCAxTXIE

 

Manual = Bible :D

Link to post
Share on other sites
  • 3 weeks later...

... and now it doesn't work :(

It is really getting frusterating, I've been trying to get serial comms working for 2-3 hours trying the programs that worked before, and even getting energia and using the serial libs on there...

has anyone experienced serial comms problems under linux (specifically ubuntu 12)? are there any better boards than the launch pad with better usb-serial bridges?

Link to post
Share on other sites

has anyone experienced serial comms problems under linux (specifically ubuntu 12)? are there any better boards than the launch pad with better usb-serial bridges?

Yes, before I patched my kernel I couldn't use the serial port on ubuntu 11.04. Once I patched my kernel, it was fine. If you want better serial support, you can purchase an FTDI usb converter or a pl2303hx converter. With those devices you would disconnected the j3 serial jumpers and plug your tx/rx pins into the usb converter tx/rx. Both of those devices have great driver support on linux and can use higher baud rates with your msp430. However, both are going to cost more than the msp430 launchpad itself.
Link to post
Share on other sites

If i'm reading that right, you are using the TX isr to trigger the same isr in rapid succession....not sure of the implications of that.  The original code also did not wait for the TX buffer to be ready for writing.  I think if you move the loop to main and make your transmit function wait for the buffer, it might work better.

 

try something like:

 

void transmit_char(int pos) {
       while (! (UCA0TXIFG & IFG2));
        UCA0TXBUF = pi[pos]; 
}

 

and call it inside main.

 

In psuedo code:

 

interrupt(USCIAB0TX_VECTOR) uart_transmit_isr() {
    P1OUT ^= BIT6 | BIT0;
}
 
void main() {
    WDTCTL = WDTPW + WDTHOLD;
 
    // configure clocks
    DCOCTL = CALDCO_16MHZ;
    BCSCTL1 = CALBC1_16MHZ;
 
    // i/o
    P1DIR = BIT6 | BIT0;
    P1OUT = 0x00;
 
    P1SEL |= BIT1 | BIT2;
    P1SEL2 |= BIT1 | BIT2;
 
    // initialise usci
    UCA0CTL1 |= UCSSEL_2; // hold reset, set smclk
    UCA0BR0 = 0x82;
    UCA0BR1 = 0x06;
    UCA0MCTL = UCBRS2 | UCBRS1;
 
    UCA0CTL1 &= ~(UCSWRST);
 
    IE2 |= UCA0TXIE;
 
    __enable_interrupt();
 
   //Transmit the chars
   while(1)
   {
    transmit_char(pos);
    pos++;
        if (pi[pos] == '\0') pos = 0;
   }
 
}
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...