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.

TL16C752D: Writing and Reading the Registers during initialization

Part Number: TL16C752D

I am in the process of initializing the registers in the TL16C752 UART with my Atmega2560 Processor. The problem I am having is:

  • I write the register (LCR for example) with the settings I need.
  • I can then turn around and read it correctly
  • When I write the next register (DLL for instance) and turn around and read it, it is correct
  • When I try to go back and read the LCR register it displays what I wrote to the DLL

The steps  I am using for a Write are:

  • Set Chip Select
  • Set the Address Lines with GPIO Port Pins
  • Select IOW / Deselect IOR
  • Write the Data to D0-D7

The steps  I am using for a Read are:

  • Set Chip Select
  • Set the Address Lines with GPIO Port Pins
  • Select IOR  /Deselect IOW
  • Read the Data from D0-D7

I'm trying to accomplish this without writing and reading registers that need advanced access. i do have to set the LCR Divisor Latch Enable bit, After writing the DLL, I return the LCR back to it's original setting.

I'm following the steps in the data sheet section Typical Application

We are using an 18.432 MHz crystal for the clock so that I can get 115200 Baud.

Thanks for your help,

Reif Heck

  • Hi Reif,

    Your read and write operations seem to be correct. Are you seeing this behavior with all of the registers in the device, or only certain ones? I will take a deeper look into this once I am back in the office on Monday and see if I can come up with some explanation for what you are seeing.

    Regards,
    Max
  • Hi Max,

    Yes I am seeing this with all of the registers. I initialize all of the registers on startup.

    If I only initialize the LCR, I can keep writing and reading different values to it.

    If initialize other registers (DLL for instance), I can keep writing and reading different values successfully.

    But if i try to go back and read the LCR, the value is stuck at whatever is in the DLL.

    I'm using an atmega2560 and have the D0-D7 buss connected to an 8 bit GPIO port (PORTA).

    To write to the TL16C752, I set the port direction as output and set the port with the 8 bit value (PINA = 8 bit value).

    To read from the TL16C752, I set the port direction as input and read PINA (char = PINA)

    I'm trying to find a way to hook my logic analyzer up to the chip but the pin spacing is so small that I can't hook the chip clips to it. I may have to try and solder wires to D0-D7.

    Thanks for the help Max,

    Reif Heck

    Finna Group

  • Hi Max,

    I was wondering what latches the input/output on D0-D7? I was looking at the data sheet for the TL16C752B and it says the read data is latched on the high to low transition of the IOR pin. Write data is latched into the register on a Low to High transition of the IOW pin. I tried this but it doesn't seem to make a difference.

    Thanks,
    Reif Heck
    Finna Group
    reif.heck@finnagroup.com
  • Hi Max,

    I forgot to mention we are using the TL16C752D part.

    Reif
  • Reif,

    What you are trying to do is correct, so my guess is there is either some "analog" issue (i.e., poor connectivity, short circuits, etc.) or some missed step in your write/read sequences. Just to be clear on the software - you mentioned using PORTA/PINA for the D[7:0] bus, but how are you controlling A[2:0] and IOW/IOR? Is this using a similar GPIO bank? (And, are you sure that it is properly toggling the address lines? You might want to check the PINx register to make sure it matches the PORTx values that you are writing.)

    When you switch from a read to a write, do you use the DDRA register in ATmega2560 to configure the GPIO bank as an inputs rather than outputs?

    You described your write/read procedures a little bit already, but can you double-check to make sure that they are aligned with the timing diagrams given in Figures 1 and 2 of the TL16C752 datasheet? That is, for a write A[2:0] should be valid, then /CS goes low, then /IOW goes low (after sufficient set-up time on the address), the D[7:0] values should be stable, then after sufficient set-up time /IOW can transition high (making sure that the minimum strobe width is not violated), followed by de-assertion of /CS. A read would be similar in that the desired address would be stable on A[2:0], then /CS goes low, then /IOR goes low, then D[7:0] toggles to match the register value (which can be read on PINA after a sufficient delay for stabilization), after which /IOW can go high, /CS can go high, and then the A[2:0] values can change to a different state.

    In case there is an issue related to something like set-up/hold timing, it may be useful as a debug measure to insert some delays in your code so that the speed of execution slows down.

    Regards,
    Max
  • Hi Max,

    I'm using a different GPIO Bank (PORTC for all of the control lines to the UART like IOW/IOR and A0-A2). I use DDRA = 0xFF for Outputs and DDRA = 0x00 for inputs.

    So it does look like I'm using the correct steps for reading and writing. I was mainly concerned that I was doing the steps in the wrong order.

    I am probably seeing a timing issue and will see if inserting delays when setting the Address and IOW/IOR lines.

    Again, my main concern was making sure I was following the correct steps.

    I'll get back in touch with you if I still can't get it to work.

    Thank you for your help Max,

    Reif

  • Hi Max,

    Well some people should not be allowed to write firmware ;~)

    For some reason I had it in my head that I could use PINA as I/O for writing and reading D0-D7. After going back over some of my other code,

     I found that Data is written out PORTA and Data is read from PINA.

    It's like my grandmother always said "Never Rule Out Stupidity!"

    Thanks for all of your input. I believe we can close this one out.

    Reif

  • Reif,

    Thanks for the update, and I'm glad this is resolved! The PORTA vs. PINA distinction confused me as well when I was reviewing the ATmega2560 datasheet earlier. I only understood it after I found some more details on a different discussion forum.

    If you encounter any other issues in implementing our device please just let us know.

    Best regards,
    Max