SparkFun Forums 

Where electronics enthusiasts find answers.

By smithron99
#201865
Hi there,

I'm trying to drive the serLCD (LCD-14073) from an ARM Cortex M4 using SPI. Both are new to me :? The challenge I'm having is the M4 doesn't support SPI at 9600 baud. Is there any way to hard-wire the board to 1 Mhz? Any chance master and slave will negotiate this themselves? Reading I've done so far on SPI seems to suggest this is a possibility. I can't use I2C, and would rather not use UART as I'm currently using the UART to communicate from the M4 board back to the PC.

Also, any guidance you might provide on 'mode' and bit order (see below) would be greatly appreciated:
Code: Select all
typedef enum
{
    NRF_DRV_SPI_MODE_0 = NRF_SPI_MODE_0, ///< SCK active high, sample on leading edge of clock.
    NRF_DRV_SPI_MODE_1 = NRF_SPI_MODE_1, ///< SCK active high, sample on trailing edge of clock.
    NRF_DRV_SPI_MODE_2 = NRF_SPI_MODE_2, ///< SCK active low, sample on leading edge of clock.
    NRF_DRV_SPI_MODE_3 = NRF_SPI_MODE_3  ///< SCK active low, sample on trailing edge of clock.
} nrf_drv_spi_mode_t;

/**
 * @brief SPI bit orders.
 */
typedef enum
{
    NRF_DRV_SPI_BIT_ORDER_MSB_FIRST = NRF_SPI_BIT_ORDER_MSB_FIRST, ///< Most significant bit shifted out first.
    NRF_DRV_SPI_BIT_ORDER_LSB_FIRST = NRF_SPI_BIT_ORDER_LSB_FIRST  ///< Least significant bit shifted out first.
} nrf_drv_spi_bit_order_t;
By smithron99
#201889
Thanks Wangcheung. I have reviewed the hookup guide several times, as well as the HD44780 datasheet. If the information is there, I must be missing it. Perhaps you could direct me. Note the pre-requisite for changing baud is first being able to send a command at 9600 baud, which I cannot. I have been able to build and flash the firmware, so I may just edit the firmware default to 100000 bps. Still not sure what SPI mode or bit order to use, though.
By wangcheung
#201929
the github code link is in the hookup guide, in there you will find:
// Initialize SPI, sets up hardware pins and enables spi and receive interrupt
// SPI is set to MODE 0 (CPOL=0, CPHA=0), slave mode, LSB first

from there you can set the SPI rate after you establish communications
By smithron99
#201937
Thanks Wangcheung,
I've got it talking to me, but as Mode 0, MSB first. Unfortunately, it seems illiterate though.

In debugging, I've repeatedly gone through the sequence:

Soft reset
clear
set cursor
send text "Hello World"

I added the soft reset later as a sanity measure, but it hasn't made any difference.

I'd say I get the text "Hello World" maybe 1 time in 10. The other nine times, I get things like:
"Hell wold"
"eellowold"
"ello wod"
etc.

I've tried an emergency reset. No improvement.
I've tried stepping down the speed. Same. :?

I've also played around a bit with contrast and the background light, which seem to work ok.
By smithron99
#201948
I've been able to get the display to print reliably if I send a single character at a time (the Nordic SPI library nrf_drv_spi_transfer() accepts a buffer of arbitrary length). I'm able to manipulate backlight colour, contrast, do a software reset and display the firmware version (1.1).


Cursor manipulation is very flakey. Thus far, I'm unable to get it to display anything on the second row. On the first row, as a test, I'm looping through printing 2-characters at column 7, with a 200 ms delay in between. The actual cursor setting seems to vary by up to two positions left or right.

Is this thing a dud?
By smithron99
#201949
Managed to get text showing on row 2 by explicitly setting the screen format to 16x2. Power-cycled the device for good measure. Since then text is so dim it's barely perceptible, and brightness, contrast, colour don't seem to improve it any. Cursor positioning issues persist. Emergency reset doesn't seem to work anymore.
By smithron99
#201951
I must have toggled the "ignore RX on startup" in my early fumbling. Toggled it explicitly and I have emergency reset working again.
Cursor position seems to work ok if I limit string displays to one character at a time. Refresh rate on this screen is downright lethargic, though :-(