Library for LCD ACM1602NI connected using I2C on Nucleo F401 is not to be found. Using I2C class offered by mbed, I cannot program for this LCD on Nucleo F401. So I programmed for this LCD to control by direct accsessing registors for I2C in STM32F401RE. Nucleo F401 で使用できる,I2C 接続の LCD ACM1602NI 用のライブラリ.このライブラリでは,I2C クラスのコンストラクタとクロック周波数設定のメンバ関数は使っているが,その他のメンバ関数などは使っていない.その理由は,タイミングの関係だと思うが,I2C クラスのメンバ関数では正常に動くプログラムを,どうしても作れないことによる.しょうがないので,MCU の I2C 関係のレジスタに直接アクセスするようなプログラムを作ったたところ,動くようになった.Nucleo の F401RE 以外については確認していない.動かない場合は,I2C 用のレジスタのアドレスを,使っている MCU に応じて書きかえる必要がある.
Dependents: ACM1602NI_Nucleo_Demo
ACM1602NI.hpp
00001 //------------------------------------------------------ 00002 // Class for LCD, ACM1602NI (Header) 00003 // 00004 // Default pin assignments 00005 // D14 SDA ---- to pin5 of LCD module 00006 // D15 SCL ---- to pin4 of LCD module 00007 // 00008 // Assignment of I2C ports 00009 // SDA SCL 00010 // I2C1 PB_7 or PB_9(D14) PB_6(D10) or PB_8(D15) 00011 // I2C2 PB_3(D3) PB_10(D6) 00012 // I2C3 PB_4(D5) or PC_9 PA_8(D7) 00013 // 00014 // 2014/08/27, Copyright (c) 2014 MIKAMI, Naoki 00015 //------------------------------------------------------ 00016 00017 #ifndef ACM1602NI_HPP 00018 #define ACM1602NI_HPP 00019 00020 #include "mbed.h" 00021 00022 namespace Mikami 00023 { 00024 class Acm1602Ni 00025 { 00026 public: 00027 // Constructor 00028 Acm1602Ni(PinName sda = D14, // SDA 00029 PinName scl = D15, // SCL 00030 uint32_t clock = 100000, // clock: 100 kHz 00031 bool cursor = false, // cursor: off 00032 bool blink = false); // blink: off 00033 // Return false if LCD is not connected 00034 bool GetOk() { return connected_; } 00035 // All clear 00036 bool Clear(); 00037 // Send command 00038 bool WriteCmd(uint8_t cmd) { return LcdTx(0x00, cmd); } 00039 // Write character 00040 void WriteChar(char data) { LcdTx(0x80, data); } 00041 // Specify display position, x: 0 - 15, y: 0, 1 00042 void SetXY(uint8_t x = 0, uint8_t y = 0) { WriteCmd(x + y*0x40 | 0x80);} 00043 // Write string from specified position 00044 void WriteString(const char str[], uint8_t x = 0, uint8_t y = 0); 00045 // Clear of specified line 00046 void ClearLine(uint8_t line) 00047 { WriteString(" ", 0, line); } 00048 00049 private: 00050 // Slave address of ACM1602NI (0x50) 00051 static const uint8_t LCD_ADDRESS_ = 0x50 << 1; // left-justified 7-bit address 00052 00053 bool connected_; // Set false in constructor if LCD is not connected 00054 00055 bool LcdTx(uint8_t cmdData, uint8_t data); 00056 bool Start(); 00057 00058 // Forbid to use copy constructor 00059 Acm1602Ni(const Acm1602Ni&); 00060 // Forbid to use substitution operator 00061 Acm1602Ni& operator=(const Acm1602Ni&); 00062 00063 uint32_t* i2c_cr1_; // pointer to I2C_CR1 (control register 1) 00064 uint32_t* i2c_dr_; // pointer to I2C_DR (data register) 00065 uint32_t* i2c_sr1_; // pointer to I2C_SR1 (status register 1) 00066 uint32_t* i2c_sr2_; // pointer to I2C_SR2 (status register 2) 00067 I2C i2c_; // Object of I2C 00068 00069 // For check contents of register 00070 bool Check(uint32_t* rg, uint16_t value) 00071 { return value == ((*rg) & value); } 00072 00073 void TxDR(uint8_t data) { *i2c_dr_ = data; } 00074 void SetCR1(uint16_t data) { *i2c_cr1_ |= data; } 00075 }; 00076 } 00077 #endif // ACM1602NI_HPP
Generated on Wed Jul 13 2022 09:31:04 by 1.7.2