我想通過SPI協議將諾基亞5110 LCD連接到BeagleBone Black Rev-C。諾基亞5110 LCD初始化問題
的連接完全一樣的6頁上顯示: Nokia5110-BeagleBone Black Connections
我寫了一個C當量的Arduino的飛利浦PCD8544代碼(諾基亞3310)驅動程序。 我在哪裏輸出所需的GPIO端口並通過SPI接口發送命令和數據。
我成功安裝並運行Adafruit的的蟒蛇庫: Adafruit Nokia LCD
我的問題是
我有一個奇怪的問題,當我第一次,然後運行這個Python代碼我的C代碼,代碼工作完美! 但是,如果我在python代碼之前運行我的C代碼,我沒有輸出。邏輯說,python 代碼必須初始化我在我的代碼中缺少的東西。
下面是如何初始化LCD:
fd_spi_dev = open(device, O_RDWR);
//set mode
mode = SPI_MODE_0;
ioctl(fd_spi_dev, SPI_IOC_WR_MODE, &mode);
ioctl(fd_spi_dev, SPI_IOC_RD_MODE, &mode);
//set max bitrate
speed = 4000000;
ioctl(fd_spi_dev, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
ioctl(fd_spi_dev, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
// set an msb first
lsbsetting = 0;
ioctl(fd_spi_dev, SPI_IOC_WR_LSB_FIRST, &lsbsetting);
// set bits per word
bits = 8;
ioctl(fd_spi_dev, SPI_IOC_WR_BITS_PER_WORD, &bits);
ioctl(fd_spi_dev, SPI_IOC_RD_BITS_PER_WORD, &bits);
lcd_write_cmd(0x21); // LCD extended commands
lcd_write_cmd(0xB8); // set LCD Vop (contrast)
lcd_write_cmd(0x04); // set temp coefficient
lcd_write_cmd(0x14); // set biad mode 1:40
lcd_write_cmd(0x20); // LCD basic commands
lcd_write_cmd(0x09); // LCD all segments on
/* I am expecting to see all segments lit here */
sleep(5);
lcd_write_cmd(0x0C); // LCD normal video
void lcd_write_cmd(uint8_t cmd) {
uint8_t *tx = &cmd;
uint8_t rx;
uint32_t len = 1;
struct spi_ioc_transfer tr = {
.tx_buf = (uint32_t)tx,
.rx_buf = (uint32_t)&rx,
.len = len,
.delay_usecs = delay,
.speed_hz = speed,
.bits_per_word = bits,
.cs_change = 1,
};
size = write(fd_dc_val, "0", 1);
size = write(fd_cs_val, "0", 1);
ioctl(fd_spi_dev, SPI_IOC_MESSAGE(1), &tr);
write(fd_cs_val, "1", 1);
}
我在嵌入式編程新手。我將不勝感激任何幫助。謝謝。