Hi everyone, I'm trying to set up the USART on my MSP430 as a UART... The initialization & putchar code is shown below. Hoever, after initializing the UART, the TX line is just held high... I thought this might be something to do with the order that I reset the SWRST bit, but i tried that, but still nothing happens on the TX line.. the ACLK is definately oscillating, as i've got a PWM outputting on another pin that uses the same clock source... Does anyone have any suggestions as to why the UART isn't getting initialised properly? void COMM_uart0_init(void) { // USART Settings: // UART function, Idle line multiprocessor Protocol, UCTL0 &=~ SWRST; // reset SWRST bit UCTL0 = CHAR; // 8-bit, 1 stop, no parity UBR00 = 0xD0; // 9600 baud (CLK 526,628hz div 9600 54) UBR10 = 0x00; UMCTL0 = 0x92; // modulation is 11110111 for 526.628khz UTCTL0 = 0x00; // external 526k clock on pin P3.3 is used URCTL0 = 0x00; ME2 |= URXE0+UTXE0; // enable USART transmit and Rx IE1 |= URXIE0+UTXIE0; // Enable Tx and Rx interrupt. } my putchar function is as follows: void putchar(UCHAR byte) { // wait until UTXIFG0 flag is set to 1, indicating // that another byte can be put in the buffer.. while (!(IFG2 & UTXIFG0)); // Put byte into buffer to be transmitted... U0TXBUF = byte; } Cheers, Glenn.
UART Initialization
Started by ●February 12, 2003
Reply by ●February 12, 20032003-02-12
Hi Glenn. Remember to set the serial port pins to the correct modes to allow the UART to use them. The port SEL mask must be set high for both pins and the port direction controls must be set to output (1) for Tx and input (0) for Rx. This example is for the MSP430F449; other cpus use different port pins: //430F449 #define SER_RX0_MASK 0x20 // P2.5 - RS232-0 Rx i/p #define SER_TX0_MASK 0x10 // P2.4 - RS232-0 Tx o/p P2SEL |= (SER_RX0_MASK|SER_TX0_MASK); // P2.4,5 = USART0 TXD/RXD P2DIR |= (SER_TX0_MASK); // P2.4 output direction Regards, Hugh >> Hi everyone, I'm trying to set up the USART on my MSP430 as a UART... The initialization & putchar code is shown below. Hoever, after initializing the UART, the TX line is just held high... I thought this might be something to do with the order that I reset the SWRST bit, but i tried that, but still nothing happens on the TX line.. the ACLK is definately oscillating, as i've got a PWM outputting on another pin that uses the same clock source... Does anyone have any suggestions as to why the UART isn't getting initialised properly? void COMM_uart0_init(void) { // USART Settings: // UART function, Idle line multiprocessor Protocol, UCTL0 &=~ SWRST; // reset SWRST bit UCTL0 = CHAR; // 8-bit, 1 stop, no parity UBR00 = 0xD0; // 9600 baud (CLK 526,628hz div 9600 54) UBR10 = 0x00; UMCTL0 = 0x92; // modulation is 11110111 for 526.628khz UTCTL0 = 0x00; // external 526k clock on pin P3.3 is used URCTL0 = 0x00; ME2 |= URXE0+UTXE0; // enable USART transmit and Rx IE1 |= URXIE0+UTXIE0; // Enable Tx and Rx interrupt. } my putchar function is as follows: void putchar(UCHAR byte) { // wait until UTXIFG0 flag is set to 1, indicating // that another byte can be put in the buffer.. while (!(IFG2 & UTXIFG0)); // Put byte into buffer to be transmitted... U0TXBUF = byte; } Cheers, Glenn.
Reply by ●February 12, 20032003-02-12
I forgot to add that also you have to transmit the first character to initiate the interrupt for subsequent characters. That is until you transmit a character, you won't get a transmit character buffer empty interrupt. Using your code you must do the following (just this once) before waiting for the interrupt stuff to start working: U0TXBUF = byte; Regards, Hugh Hi Glenn. Remember to set the serial port pins to the correct modes to allow the UART to use them. The port SEL mask must be set high for both pins and the port direction controls must be set to output (1) for Tx and input (0) for Rx. This example is for the MSP430F449; other cpus use different port pins: //430F449 #define SER_RX0_MASK 0x20 // P2.5 - RS232-0 Rx i/p #define SER_TX0_MASK 0x10 // P2.4 - RS232-0 Tx o/p P2SEL |= (SER_RX0_MASK|SER_TX0_MASK); // P2.4,5 = USART0 TXD/RXD P2DIR |= (SER_TX0_MASK); // P2.4 output direction Regards, Hugh >> Hi everyone, I'm trying to set up the USART on my MSP430 as a UART... The initialization & putchar code is shown below. Hoever, after initializing the UART, the TX line is just held high... I thought this might be something to do with the order that I reset the SWRST bit, but i tried that, but still nothing happens on the TX line.. the ACLK is definately oscillating, as i've got a PWM outputting on another pin that uses the same clock source... Does anyone have any suggestions as to why the UART isn't getting initialised properly? void COMM_uart0_init(void) { // USART Settings: // UART function, Idle line multiprocessor Protocol, UCTL0 &=~ SWRST; // reset SWRST bit UCTL0 = CHAR; // 8-bit, 1 stop, no parity UBR00 = 0xD0; // 9600 baud (CLK 526,628hz div 9600 54) UBR10 = 0x00; UMCTL0 = 0x92; // modulation is 11110111 for 526.628khz UTCTL0 = 0x00; // external 526k clock on pin P3.3 is used URCTL0 = 0x00; ME2 |= URXE0+UTXE0; // enable USART transmit and Rx IE1 |= URXIE0+UTXIE0; // Enable Tx and Rx interrupt. } my putchar function is as follows: void putchar(UCHAR byte) { // wait until UTXIFG0 flag is set to 1, indicating // that another byte can be put in the buffer.. while (!(IFG2 & UTXIFG0)); // Put byte into buffer to be transmitted... U0TXBUF = byte; } Cheers, Glenn.
Reply by ●February 12, 20032003-02-12
Actually, you can just do "UCSR1B |= (1 << UDRIE1);", which means when you're doing interrupt I/O, you don't have to special case your putchar() routine to see if you've already got data outgoing already or not. --John -----Original Message----- From: Hugh Molesworth [mailto:nzbackpackers@nzba...] Sent: Wednesday, February 12, 2003 17:55 To: msp430@msp4... Subject: Re: [msp430] UART Initialization I forgot to add that also you have to transmit the first character to initiate the interrupt for subsequent characters. That is until you transmit a character, you won't get a transmit character buffer empty interrupt. Using your code you must do the following (just this once) before waiting for the interrupt stuff to start working: U0TXBUF = byte; Regards, Hugh [ snip ]
Reply by ●February 12, 20032003-02-12
ok, thanks Hugh... i forgot to mention that I set up the ports in a different function...here's an updated version of the UART initialization: the baud rate is 38400, running off an 8MHz external XTAL... i don't think it could be wrong values in any of the baud rate registers, because even if i had them wrong, i'd get some sort of waveform on the output... at the moment, the pin just gets held high... the first character gets put into the TX buffer, the the next putbyte gets stuck waiting for: while (!(IFG2 & UTXIFG0)); Note that i haven't enabled interrupts in this version, though it shouldn't affect the flag getting set... it's as if the character just doesn't get sent out of the UART? void usart0_init() //Clock sourceLK //Desired baud8400 //Actual baud8392 { UCTL0 &=~ SWRST; // reset SWRST bit UCTL0 = 0x10; //CHAR0, 8-bit mode.. // Select ACLK as source for UART... UTCTL0=0x10;//SSEL0.0 // UART receive status... URCTL0=0x00; // Divider for clock of 38400 // 8000000/38400 = 208.33 // 208 DEC = 0x00D0 HEX U0BR1=0x00; U0BR0=0xD0; // Modulation: 0x92 UMCTL0=0x92; // Selected 8-bit character mode... P3SEL |= 0x30; //BIT5+BIT4; // Pin P3.5 and P3.4 and P3.3 used by USART module P3DIR |= 0x10; // BIT4; // Pin P3.4 is output } -----Original Message----- From: Hugh Molesworth [mailto:nzbackpackers@nzba...] Sent: Thursday, 13 February 2003 11:55 a.m. To: msp430@msp4... Subject: Re: [msp430] UART Initialization I forgot to add that also you have to transmit the first character to initiate the interrupt for subsequent characters. That is until you transmit a character, you won't get a transmit character buffer empty interrupt. Using your code you must do the following (just this once) before waiting for the interrupt stuff to start working: U0TXBUF = byte; Regards, Hugh Hi Glenn. Remember to set the serial port pins to the correct modes to allow the UART to use them. The port SEL mask must be set high for both pins and the port direction controls must be set to output (1) for Tx and input (0) for Rx. This example is for the MSP430F449; other cpus use different port pins: //430F449 #define SER_RX0_MASK 0x20 // P2.5 - RS232-0 Rx i/p #define SER_TX0_MASK 0x10 // P2.4 - RS232-0 Tx o/p P2SEL |= (SER_RX0_MASK|SER_TX0_MASK); // P2.4,5 = USART0 TXD/RXD P2DIR |= (SER_TX0_MASK); // P2.4 output direction Regards, Hugh >> Hi everyone, I'm trying to set up the USART on my MSP430 as a UART... The initialization & putchar code is shown below. Hoever, after initializing the UART, the TX line is just held high... I thought this might be something to do with the order that I reset the SWRST bit, but i tried that, but still nothing happens on the TX line.. the ACLK is definately oscillating, as i've got a PWM outputting on another pin that uses the same clock source... Does anyone have any suggestions as to why the UART isn't getting initialised properly? void COMM_uart0_init(void) { // USART Settings: // UART function, Idle line multiprocessor Protocol, UCTL0 &=~ SWRST; // reset SWRST bit UCTL0 = CHAR; // 8-bit, 1 stop, no parity UBR00 = 0xD0; // 9600 baud (CLK 526,628hz div 9600 54) UBR10 = 0x00; UMCTL0 = 0x92; // modulation is 11110111 for 526.628khz UTCTL0 = 0x00; // external 526k clock on pin P3.3 is used URCTL0 = 0x00; ME2 |= URXE0+UTXE0; // enable USART transmit and Rx IE1 |= URXIE0+UTXIE0; // Enable Tx and Rx interrupt. } my putchar function is as follows: void putchar(UCHAR byte) { // wait until UTXIFG0 flag is set to 1, indicating // that another byte can be put in the buffer.. while (!(IFG2 & UTXIFG0)); // Put byte into buffer to be transmitted... U0TXBUF = byte; } Cheers, Glenn. . ">http://docs.yahoo.com/info/terms/
Reply by ●February 12, 20032003-02-12
I see you're using IFG2 instead of IFG1. Try this instead: while (!(IFG1 & UTXIFG0)); Good luck! Hugh >>ok, thanks Hugh... i forgot to mention that I set up the ports in a different function...here's an updated version of the UART initialization: the baud rate is 38400, running off an 8MHz external XTAL... i don't think it could be wrong values in any of the baud rate registers, because even if i had them wrong, i'd get some sort of waveform on the output... at the moment, the pin just gets held high... the first character gets put into the TX buffer, the the next putbyte gets stuck waiting for: while (!(IFG2 & UTXIFG0)); Note that i haven't enabled interrupts in this version, though it shouldn't affect the flag getting set... it's as if the character just doesn't get sent out of the UART? void usart0_init() //Clock sourceLK //Desired baud8400 //Actual baud8392 { UCTL0 &=~ SWRST; // reset SWRST bit UCTL0 = 0x10; //CHAR0, 8-bit mode.. // Select ACLK as source for UART... UTCTL0=0x10;//SSEL0.0 // UART receive status... URCTL0=0x00; // Divider for clock of 38400 // 8000000/38400 = 208.33 // 208 DEC = 0x00D0 HEX U0BR1=0x00; U0BR0=0xD0; // Modulation: 0x92 UMCTL0=0x92; // Selected 8-bit character mode... P3SEL |= 0x30; //BIT5+BIT4; // Pin P3.5 and P3.4 and P3.3 used by USART module P3DIR |= 0x10; // BIT4; // Pin P3.4 is output }
Reply by ●February 12, 20032003-02-12
sorry, i should have specified the device.... msp430f1222 the UTXIFG0 register is in IFG2... -----Original Message----- From: Hugh Molesworth [mailto:nzbackpackers@nzba...] Sent: Thursday, 13 February 2003 12:39 p.m. To: msp430@msp4... Subject: RE: [msp430] UART Initialization I see you're using IFG2 instead of IFG1. Try this instead: while (!(IFG1 & UTXIFG0)); Good luck! Hugh >>ok, thanks Hugh... i forgot to mention that I set up the ports in a different function...here's an updated version of the UART initialization: the baud rate is 38400, running off an 8MHz external XTAL... i don't think it could be wrong values in any of the baud rate registers, because even if i had them wrong, i'd get some sort of waveform on the output... at the moment, the pin just gets held high... the first character gets put into the TX buffer, the the next putbyte gets stuck waiting for: while (!(IFG2 & UTXIFG0)); Note that i haven't enabled interrupts in this version, though it shouldn't affect the flag getting set... it's as if the character just doesn't get sent out of the UART? void usart0_init() //Clock sourceLK //Desired baud8400 //Actual baud8392 { UCTL0 &=~ SWRST; // reset SWRST bit UCTL0 = 0x10; //CHAR0, 8-bit mode.. // Select ACLK as source for UART... UTCTL0=0x10;//SSEL0.0 // UART receive status... URCTL0=0x00; // Divider for clock of 38400 // 8000000/38400 = 208.33 // 208 DEC = 0x00D0 HEX U0BR1=0x00; U0BR0=0xD0; // Modulation: 0x92 UMCTL0=0x92; // Selected 8-bit character mode... P3SEL |= 0x30; //BIT5+BIT4; // Pin P3.5 and P3.4 and P3.3 used by USART module P3DIR |= 0x10; // BIT4; // Pin P3.4 is output } . ">http://docs.yahoo.com/info/terms/
Reply by ●February 12, 20032003-02-12
The plot thickens ... With the x1xxx family you have to enable UTXE0 & URXE0 which on the 1222 is in ME2, so I believe. Try ME2 |= (UTXE0|URXE0); Regards, HUgh ================================ >sorry, i should have specified the device.... msp430f1222 i forgot to mention that I set up the ports in a different function...here's an updated version of the UART initialization: the baud rate is 38400, running off an 8MHz external XTAL... i don't think it could be wrong values in any of the baud rate registers, because even if i had them wrong, i'd get some sort of waveform on the output... at the moment, the pin just gets held high... the first character gets put into the TX buffer, the the next putbyte gets stuck waiting for: while (!(IFG2 & UTXIFG0)); Note that i haven't enabled interrupts in this version, though it shouldn't affect the flag getting set... it's as if the character just doesn't get sent out of the UART? void usart0_init() //Clock sourceLK //Desired baud8400 //Actual baud8392 { UCTL0 &=~ SWRST; // reset SWRST bit UCTL0 = 0x10; //CHAR0, 8-bit mode.. // Select ACLK as source for UART... UTCTL0=0x10;//SSEL0.0 // UART receive status... URCTL0=0x00; // Divider for clock of 38400 // 8000000/38400 = 208.33 // 208 DEC = 0x00D0 HEX U0BR1=0x00; U0BR0=0xD0; // Modulation: 0x92 UMCTL0=0x92; // Selected 8-bit character mode... P3SEL |= 0x30; //BIT5+BIT4; // Pin P3.5 and P3.4 and P3.3 used by USART module P3DIR |= 0x10; // BIT4; // Pin P3.4 is output }
Reply by ●February 12, 20032003-02-12
Oops, forgot to put that part in... had it in the first one, but not the second... anyway, after enabling the TX & RX, the putbyte routine no longer gets stuck waiting for the TX buffer to be cleared... this suggests that the byte is now getting sent out of the UART... however, still nothing on the CRO... the line is still being held high, with no UART activity at all... To test this, i set the uart up with a TX interrupt... the interrupt never gets entered.. i have enabled global interrupts, and have enabled the specific RX/TX interrupts with: // Enable TX & RX interrupt... IE2 |= URXIE0|UTXIE0; and the ISR is: // UART0 TX Interrupt vector. // Doesn't do anything, just seeing if it is entered... interrupt [UART0TX_VECTOR ] void UART0_TX(void) { int i; for (i=0;i<64;i++) { i++; } } It never reaches a break-point in the ISR on the i++ line... i'm a bit lost on this one... Anyway, thanks for your help on this one Hugh. ps. I think the AVR is easier to work with than this one? Also, the new Mega169 does have an in-built LCD port (a comment from a previous post)... -----Original Message----- From: Hugh Molesworth [mailto:nzbackpackers@nzba...] Sent: Thursday, 13 February 2003 1:10 p.m. To: msp430@msp4... Subject: RE: [msp430] UART Initialization The plot thickens ... With the x1xxx family you have to enable UTXE0 & URXE0 which on the 1222 is in ME2, so I believe. Try ME2 |= (UTXE0|URXE0); Regards, HUgh ================================ >sorry, i should have specified the device.... msp430f1222 i forgot to mention that I set up the ports in a different function...here's an updated version of the UART initialization: the baud rate is 38400, running off an 8MHz external XTAL... i don't think it could be wrong values in any of the baud rate registers, because even if i had them wrong, i'd get some sort of waveform on the output... at the moment, the pin just gets held high... the first character gets put into the TX buffer, the the next putbyte gets stuck waiting for: while (!(IFG2 & UTXIFG0)); Note that i haven't enabled interrupts in this version, though it shouldn't affect the flag getting set... it's as if the character just doesn't get sent out of the UART? void usart0_init() //Clock sourceLK //Desired baud8400 //Actual baud8392 { UCTL0 &=~ SWRST; // reset SWRST bit UCTL0 = 0x10; //CHAR0, 8-bit mode.. // Select ACLK as source for UART... UTCTL0=0x10;//SSEL0.0 // UART receive status... URCTL0=0x00; // Divider for clock of 38400 // 8000000/38400 = 208.33 // 208 DEC = 0x00D0 HEX U0BR1=0x00; U0BR0=0xD0; // Modulation: 0x92 UMCTL0=0x92; // Selected 8-bit character mode... P3SEL |= 0x30; //BIT5+BIT4; // Pin P3.5 and P3.4 and P3.3 used by USART module P3DIR |= 0x10; // BIT4; // Pin P3.4 is output } . ">http://docs.yahoo.com/info/terms/
Reply by ●February 12, 20032003-02-12
ok, got the UART working... ended up using some example code from the TI website... i must have changed something in it before that stuffed up the initialization... but thanks for all your help on that one Hugh... -----Original Message----- From: Glenn Richmond Sent: Thursday, 13 February 2003 2:46 p.m. To: 'msp430@'msp...' Subject: RE: [msp430] UART Initialization Oops, forgot to put that part in... had it in the first one, but not the second... anyway, after enabling the TX & RX, the putbyte routine no longer gets stuck waiting for the TX buffer to be cleared... this suggests that the byte is now getting sent out of the UART... however, still nothing on the CRO... the line is still being held high, with no UART activity at all... To test this, i set the uart up with a TX interrupt... the interrupt never gets entered.. i have enabled global interrupts, and have enabled the specific RX/TX interrupts with: // Enable TX & RX interrupt... IE2 |= URXIE0|UTXIE0; and the ISR is: // UART0 TX Interrupt vector. // Doesn't do anything, just seeing if it is entered... interrupt [UART0TX_VECTOR ] void UART0_TX(void) { int i; for (i=0;i<64;i++) { i++; } } It never reaches a break-point in the ISR on the i++ line... i'm a bit lost on this one... Anyway, thanks for your help on this one Hugh. ps. I think the AVR is easier to work with than this one? Also, the new Mega169 does have an in-built LCD port (a comment from a previous post)... -----Original Message----- From: Hugh Molesworth [mailto:nzbackpackers@nzba...] Sent: Thursday, 13 February 2003 1:10 p.m. To: msp430@msp4... Subject: RE: [msp430] UART Initialization The plot thickens ... With the x1xxx family you have to enable UTXE0 & URXE0 which on the 1222 is in ME2, so I believe. Try ME2 |= (UTXE0|URXE0); Regards, HUgh ================================ >sorry, i should have specified the device.... msp430f1222 i forgot to mention that I set up the ports in a different function...here's an updated version of the UART initialization: the baud rate is 38400, running off an 8MHz external XTAL... i don't think it could be wrong values in any of the baud rate registers, because even if i had them wrong, i'd get some sort of waveform on the output... at the moment, the pin just gets held high... the first character gets put into the TX buffer, the the next putbyte gets stuck waiting for: while (!(IFG2 & UTXIFG0)); Note that i haven't enabled interrupts in this version, though it shouldn't affect the flag getting set... it's as if the character just doesn't get sent out of the UART? void usart0_init() //Clock sourceLK //Desired baud8400 //Actual baud8392 { UCTL0 &=~ SWRST; // reset SWRST bit UCTL0 = 0x10; //CHAR0, 8-bit mode.. // Select ACLK as source for UART... UTCTL0=0x10;//SSEL0.0 // UART receive status... URCTL0=0x00; // Divider for clock of 38400 // 8000000/38400 = 208.33 // 208 DEC = 0x00D0 HEX U0BR1=0x00; U0BR0=0xD0; // Modulation: 0x92 UMCTL0=0x92; // Selected 8-bit character mode... P3SEL |= 0x30; //BIT5+BIT4; // Pin P3.5 and P3.4 and P3.3 used by USART module P3DIR |= 0x10; // BIT4; // Pin P3.4 is output } . ">http://docs.yahoo.com/info/terms/ . ">http://docs.yahoo.com/info/terms/