Class library for LCD character display ACM1602NI using I2C on Nucleo. Nucleo 用 I2C 接続の LCD キャラクタ・ディスプレー ACM1602Ni 用のクラス・ライブラリ.

Dependents:   UIT2_VariableFIR_LPFHPF UIT2_VariableFIR_LPF UIT2_InputSW_LCD ADDA_Prototype_PollingSW ... more

Revision:
7:fd23d2941f36
Parent:
6:b911485a6f4d
Child:
8:6f28524bcb29
diff -r b911485a6f4d -r fd23d2941f36 ACM1602NI.cpp
--- a/ACM1602NI.cpp	Sun Dec 14 07:43:01 2014 +0000
+++ b/ACM1602NI.cpp	Sat Jan 17 09:59:57 2015 +0000
@@ -1,7 +1,7 @@
 //-------------------------------------------------------
 //  Class for LCD, ACM1602Ni
 //
-//  2014/12/14, Copyright (c) 2014 MIKAMI, Naoki
+//  2015/01/17, Copyright (c) 2015 MIKAMI, Naoki
 //-------------------------------------------------------
 
 #include "ACM1602NI.hpp"
@@ -60,52 +60,38 @@
     }
 
     //---------------------------------------------------
-    // Following functions: private
+    // Following member functions: private
 
     // Send command and data
     bool Acm1602Ni::LcdTx(uint8_t cmdData, uint8_t data)
     {
         if (!Start()) return false;
+        
         // defines kind of "data" in next statement
         TxDR(cmdData);
         TxDR(data);
         wait_us(500);   // indispensable
+        
         // Generate stop condition
-        SetCR1(I2C_CR1_STOP);
+        i2c_.stop();      
+
         return true;
     }
 
     // Preparation for send of command and data
     bool Acm1602Ni::Start()
     {
-        const uint8_t WAIT = 30;
         const uint8_t LENGTH = 10;
 
-        // wait for I2C not busy
-        for (int n=0; n<LENGTH; n++)
-        {
-            wait_us(WAIT);      
-            if (!CheckSR2(I2C_SR2_BUSY)) break;
-            if (n == LENGTH-1) return false;
-        }
-
         // Generate start condition
-        SetCR1(I2C_CR1_START);
-        // Confirm start condition and master mode
-        for (int n=0; n<LENGTH; n++)
-        {
-            wait_us(WAIT);
-            if (CheckSR12(I2C_SR1_SB, I2C_SR2_MSL |
-                                      I2C_SR2_BUSY)) break;
-            if (n == LENGTH-1) return false;
-        }
+        i2c_.start();
 
         // Send slave address
         TxDR(LCD_ADDRESS_);
         // Confirm on transmit mode
         for (int n=0; n<LENGTH; n++)
         {
-            wait_us(WAIT);      
+            wait_us(10);      
             if (CheckSR12(I2C_SR1_TXE | I2C_SR1_ADDR,
                           I2C_SR2_MSL | I2C_SR2_BUSY
                                       | I2C_SR2_TRA)) break;
@@ -115,4 +101,3 @@
         return true;
     }
 }
-