However I found 4 otherdifferent initialisation sequences. I cannot test them myself, without having one of those ICsthese devices, but I suggest trying them as a starting point, as I explained above.
- From page 7 in the NXP Application Note AN10587 - Interfacing NXP bridge IC with NXP ARM microcontroller (again this is an SPI-based example, it's for the 2-channel version of the device, and it includes initialisation of the GPIO pins, buthowever the relevant parts of the initialisation sequence are clear):
From this mbed code library:
cmd[0] = LCR << 3; cmd[1] = 0x83; // DLL,H Latch enable i2c.write(SC16IS750_ADDR, cmd, 2); cmd[0] = DLL << 3; cmd[1] = 117; // baud = 18e6 / 16 /117 = 9615 i2c.write(SC16IS750_ADDR, cmd, 2); cmd[0] = DLH << 3; cmd[1] = 0x0; i2c.write(SC16IS750_ADDR, cmd, 2); cmd[0] = LCR << 3; cmd[1] = 0x03; // NoParity 1Stop 8bits i2c.write(SC16IS750_ADDR, cmd, 2); cmd[0] = FCR << 3; cmd[1] = 0x07; // reset TX,RX FIFO, FIFO enable i2c.write(SC16IS750_ADDR, cmd, 2);
There is another mbed library containing another initialisation example. However that code is more complex and it is more difficult to extract only the relevant parts to include here. It's simpler for you to read this one at its original location.
(It is also worth noting that this device claims to have a 16C450-compatible register set (actually it is more like a 16550, since it has a FIFO, or even a 16750, since it has a 64-byte FIFO). You can review old 16550 UART literature about how that device is usually initialised. From my quick research, a sequence similar to example 2 is typical.)
One difference (which I suspect is important) between those other initialisation examples and your code, is that none of them initialise FCR
at the start and end of the sequence, as your existing code does. They either write to FCR
only once (examples 2 & 3) or write to FCR
twice in succession, with other registers programmed before that (examples 1 & 4).
- One difference (which I suspect is important) between those other initialisation examples and your code, is that none of them initialise
FCR
at the start and end of the sequence, as your existing code does. They either write toFCR
only once (examples 2 & 3) or write toFCR
twice in succession, with other registers programmed before that (examples 1 & 4).
On page 22 of the SC16IS750 datasheet, is note 4"note 4" regarding FCR
, where it says:
(ThereAs an aside, there seems to be a mistake in that note - Receive FIFO & Transmit FIFO reset bits are FCR[2:1]
not FCR [1:0]
)
Although youI don't breakknow the timing of your code, to see whether it reads RHR
too quickly after resetting the FIFO. On the surface, it seems unlikely that ruleyou are breaking that requirement - 2 clock cycles of whatever crystal Sparkfun use on your specific board (e.g. 12.288 MHz or 14.7456 MHz - check your board) is a very short minimum delay, especially when using a comparatively slow I²C bus to send commands. However I wonder if there is a hidden issue in this timing requirement, since it is clearmeasured in clock cycles of the crystal. See below where I mention the "Power-on sequence".
So as you see, it is implied by that datasheet note, that writing to (at least certain bits in) FCR
has some internal timing dependencies. Your existing code does modify other registers, after setting the Receive FIFO & Transmit FIFO reset bits in FCR
. If there is one place where a lack of mentioning other side effects in the datasheet might affect you, but not affect the other example code which I found, then it could be in thatthis area.
(It is also worth noting that this device claims to have a 16C450-compatible register set (actually it is more like a 16550, since it has a FIFO, or even a 16750, since it has a 64-byte FIFO). You can review old 16550 UART literature about how the that device was initialised. From my quick research, a sequence similar to example 2 was typical.)
- Another interesting point discussed in section 7.4.2 "Power-on sequence" in the datasheet, is the potential need for delay after power-on. As I interpret it, you should not attempt to program the registers until at least 3 µs after power-on (or after external reset pulse). That requirement may not affect you during a normal power-on, as your MCU etc. will also be initialising.
However notice the next part [my emphasis added]:
Once the device is reset properly, the host processor can start to communicate with the device. Internal registers can be accessed (read and write), however, at this time the UART transmitter and receiver cannot be used until there is a stable clock at XTAL1 pin. Normally, if an external clock such as a system clock or an external oscillator is used to supply a clock to XTAL1 pin, the clock should be stable at this time. But if a crystal is used, the host processor must wait until the crystal is generating a stable clock before accessing the UART transmitter or receiver.
The crystal’s start-up time depends on the crystal being used, VCC ramp-up time and the loading capacitor values. The start-up time can be as long as a few milliseconds.
That time is shown as "tstartup" in the following diagram - but as they say, the actual duration of tstartup is unknown, as it depends on your specific hardware.
Having explained the background, here is the main point: Perhaps that requirement in the datasheet ("note 4" on page 22) for a delay of "at least 2 x Tclk of XTAL1 before reading or writing data to RHR and THR" after resetting the FIFO, cannot start until after the crystal output is stable (i.e. until after "tstartup" has elapsed) since it is measured in clock cycles of the crystal, and you don't know when the crystal has actually started.
If you have a crystal which is slow to start, these timing requirements could be affecting you.
Therefore I would either:
- changeChange the sequence of initialisation sequence to match one of the other examples (assuming that those other example initialisation sequences do work correctly - examples 1 & 2 are from the device manufacturer, so they should work!);.
orExamples 1 & 2 are from the device manufacturer, so they should work!
and
- you could try adding a delay after programming
FCR
Consider whether one or more delays might need to set those bits atbe added during the start of yourregister initialisation sequence (the delay should be at least as long as, to comply with the worst-case timing requirements explained in that note from the datasheet, which depends on the crystal fitted to your Sparkfun breakout board - there have been at least 2 different versions).