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.

UART example for F28069

Other Parts Discussed in Thread: CONTROLSUITE

Hi all,

I have TMS320C2000 PLC kit and now I'm trying to understand the phy_tx_rx example project. In this task, I would like to know how to tx and rx by both uarts (the uart by the usb cable and the uart by rs232). I mean I would like firstly to forget the PLC part and to ensure that I know how to use uart functions; for this purpose I need to modify the phy_tx_rx project, for example, to receive bytes from any uart and transmit them back by the same uart.

When I know how to do uart tx and rx, I´ll try to link PLC tx/rx with uart tx/rx (For example, to transmit the data received from PLC to the hyperterminal by the uart).

Resuming, I need an example code for the F2806x (or compatible) to transmit and receive by uart. I only have the uart.h included with the PrimeDevelopmentPackageV60013; in this file I can see the functions headers, but I don´t know how to use them. I'd have a look into the F2806x_examples folder of the controlSUITE, but I can´t find a project with uart code (I think it is necessary to configure and initialize uart, etc...).

Anyway I'll continue searching into this examples while somebody answers this question.

Many thanks in advance for your help.

Cristóbal.

  • Cristobal,

    You're looking in the right place.  There are a few UART examples in the f2806x_examples folder, but they are not called "UART".  On C28x devices our UART is called SCI.  Try taking a look at sci_echoback, scia_loopback, and scia_loopback_interrupts.

    Let me know if you have more specific questions.

    Regards,

    Trey

  • Hi Trey,

    Thanks for your reply. I´ve tested these sci examples and they work fine. Now I'm trying to include something similar into the phy_tx_rx_vcu example which is included in PrimeDevelopmentPackageV60013, but I can´t get it. I only want (by now) to show an example welcome message by hiperterminal when I run the physical PLC example, before execution arrives to the while loop where it is waiting for a PLC packet reception.

    It seems ok because I build the project with no errors and debugger loads the code into the target. Even I can execute the code step by step and I see that sci functions are called, but the message does not appear in the hiperterminal.

    I think maybe thera are some configurations problems, but I´m not sure. I have used the same sci functions that in the sci example which works fine, and the same configuration in the hyperterminal, even I tried with others baudrates, but it doesn´t work.

    Thanks in advance for your help.

    Regards,

    Cristóbal.

  • Christobal,

    I suspect that you have a baudrate mismatch.  The PLC example probably sets up the PLL differently which is resulting in a different system clock speed.  You'll need to figure out what the system clock and low speed peripheral clock are in the new example and then setup the baud rate register accordingly.  I would recommend you take a look at the System Control and Interrupts user guide as well as the SCI user guide.

    Regards,

    Trey

  • Hi Trey,

    I thought that would be the problem. I've checked some registers configuration and I think that the plc example configures external clock as clock source. If this is the case, how can I know the frequency of the external clock? I think that it will be the frequency  of the external cristal included in the F28069 controlCARD, but I don´t know which is the value.

    I've tried to change to the internal oscilator like in the sci example (which works fine about uart tx/rx), but it is not easy for me, because there are other differences that I don´t understand.

    So I think it would be easier to try to configure scia parameters based on that external frequency...

    Thanks in advance for your help.

    Regards,

    Cristobal.

  • Hi Trey,

    I've just solved the problem. The first problem was that I don´t have the source code of the InitSysCtrl function used in the plc example; it is taken from a library. So I was confussed, but today I could see in the dissassembly window while a debug session that it seemed to configure external clock as the source clock.

    Then I needed the external clock frequency, so I asked you with the last post. Sorry, I would think more before ask. I've opened the PLC kit box and extracted the F28069 controlCARD. I've had a look to the components and I've seen that the external crystal is 20.00, so I supposed 20 MHz.

    Furthermore, I've checked some registers values that are configured inside InitSysCtrl function, and I've understood them with the "TMS320x2806x Piccolo Technical Reference Manual". I've seen that register PLLCR has value 0x0009 and register PLLSTS has value 0x0101. According to figures 1-25 and 1-26, and table 1-24, all in page 85 of that manual, I have PLLSTS[DIVSEL] = 2 and PLLCR[DIV] = 01001, so I have SYSCLKOUT = (OSCCLK * 9)/2.

    As I have the external 20 MHz crystal, my SYSCLKOUT = (20 MHz * 9)/2 = 90 MHz.

    Then I set bits LSPCLK in LOSPCP register (page 76 in manual) with the value 1, so I have the Low speed clock = SYSCLKOUT/2 = 45 MHz.

    And finally I compute the values for the registers SCIHBAUD and SCILBAUD according the formula in the manual BRR = (LSPCLK / (baudrate * 8)) - 1.

    Now the uart works fine, and I have communication with the hyperterminal.

    Thanks for all.

    Regards,

    Cristóbal.

  • Yep, you figured it out!  I know its tricky when you are new to a microcontroller, but the only way to solve complex problems like this is to break down the system and to make sure you fully understand each piece.

    Glad to hear you were able to get it working.  Let us know if you need help in the future.

    Regards,

    Trey

  • How do you get this example to work with SCI-B and not SCI-A? 

    Thank you

  • The initSysCtrl clearly executes IntOsc1Sel(); where the internal Osc1 is 10MHz, so how do you figure that the example uses the external 20MHz clock? 

  • Christian,

    To get the example to run on SCI-B simply change the init calls to reference the ScibRegs structure.  For instance you would change the line:

    SciaRegs.SCICCR.all =0x0007;

    to:

    ScibRegs.SCICCR.all =0x0007;

    In regard to the oscillator, I believe all the examples use the internal oscillator.  Where did you get that it was using the 20Mhz external clock?

    Trey

  • I tried changing all the SciaRegs to Scib but no cigar. 

    The starter of this thread says in his solution : As I have the external 20 MHz crystal, my SYSCLKOUT = (20 MHz * 9)/2 = 90 MHz

    I tried setting BAUD rates according to this with SYSCLKOUT/4 (default), getting Low Speed Clock 90MHz/4 = 22,5MHz -> baud = 22MHz/(9600 * 8) -1 which worked correctly. Trying to set baud with 10MHz as Low Speed Clock frequency I get nothing. 

    EDIT: 

    InitPeripheralClocks() has SysCtrlRegs.LOSPCP.all = 0x0002; which results in a Low Speed Clock divider of 4

  • Did you get it working or still having trouble with 10Mhz? Sorry for my confusion.

    Also if you are using the interrupt example make sure you change the interrupt vectors that the handlers are registered to.

  • I got it working by assuming 20MHz from the external crystal, but from the example code I can't understand why this is correct, as the example enables internal 10MHz RC. 

    EDIT: I am using the sci_echoback example, not interrupt driven

    To elaborate further: the example does 

    void IntOsc1Sel (void) {
    EALLOW;
    SysCtrlRegs.CLKCTL.bit.INTOSC1OFF = 0;
    SysCtrlRegs.CLKCTL.bit.OSCCLKSRCSEL=0; // Clk Src = INTOSC1
    SysCtrlRegs.CLKCTL.bit.XCLKINOFF=1; // Turn off XCLKIN
    SysCtrlRegs.CLKCTL.bit.XTALOSCOFF=1; // Turn off XTALOSC
    SysCtrlRegs.CLKCTL.bit.INTOSC2OFF=1; // Turn off INTOSC2
    EDIS;
    }

    which clearly turns on  the 10MHz internal OSC, but calculating baud with 10MHz clock gets the wrong result. Calculating with 20MHz clock gives correct result. 

  • Hi Trey,

    As Christian mentioned about the SCIB, I tried the same thing that change all the SCIA to SCIB in the echoback example, but did not get any luck to see any rx/tx coming from the usb cable to my terminal. Is there anything I might be possibly missing, I think my baud rate setting is correct.

    Thanks

    Frank 

  • Frank,

    Have you setup the GPIO muxing for SCIB and do you have the usb/serial cable plugged into the right pins?

    Trey

  • Hi Trey,

    Thanks for the quick reply,

    instead of worrying about SCIB, I switched to SCIA for now since I noticed this post http://e2e.ti.com/support/microcontrollers/tms320c2000_32-bit_real-time_mcus/f/171/p/228901/836530.aspx#836530 has a working solution.

    I just want to verify that with you, I have a female DB9 to USB adapter and I connect the 9-pin side to the PLC kit and the USB to my PC, my PC installs the driver of the adapter correctly, however, i'm not able to get any rx/tx for now. 

    Could you please verify that if the adapter may be a problem? If it is, what do you recommend for talking via SCIA (my laptop does not have the 9-pin port).

    Thank you very much for your help

    Frank

  • Frank,

    You ought to be able to use the adapter you currently have.  If you aren't seeing communication, I would suspect a baud rate mis-match.  Do you have a scope you could use to watch the SCIA TX line?  This will allow you to verify GPIO are setup correctly and the baud rate.  Measure the smallest bit you can find and take its reciprocal to find the currently configured baud rate.  Make sure this matches what you have your PC setup for.

    Trey

  • Hi Trey,

    Although I still did not figure out how the SCIA with the DB9 to USB working, I did actually get the SCIB working through the USB( which is even better then the adapter approach :)), as you mentioned earlier about the GPIO settings for SCIB, I thought example code setting are correct, however, after looking at the schematic, I figured out that for the TMS320C2000 PLC kit, the SCIB is actually set to be GPIO 15 and GPIO 14, after setting all the GPIOs for SCIB, the echoback program works just fine!

    Really appreciate your help!

    Frank