CEBF746 Module.. PC <--> This Module (SPI Master) <-->

Dependencies:   cube_CEBF746 cube_crc_16 mbed

Revision:
7:efe7a78d7724
Parent:
6:a98f9d63f8a2
diff -r a98f9d63f8a2 -r efe7a78d7724 main.cpp
--- a/main.cpp	Wed Oct 19 08:52:35 2016 +0000
+++ b/main.cpp	Thu Oct 20 13:13:19 2016 +0000
@@ -126,6 +126,8 @@
     spiDataStr sendData;
     spiDataStr reciveData;
     
+    uint8_t encTempBuf[CEB_BUF_SIZE] = {0, };            
+    
     uint8_t spiMOSIBuf[255];
     uint8_t spiMISOBuf[255];
     
@@ -199,15 +201,15 @@
             
             reciveData.size = CEB_BUF_SIZE;
             reciveData.buf = (uint8_t*)selfTempRxBuf;
-            sendData.crc16 = 0;
+            reciveData.crc16 = 0;
             
             ret = cebf746_packet_read(FUNC_READ_SELF_TEST, &reciveData);
             
             break;
         
         
-        case MENU_SPI_WRITE_ENC_DATA:            
-            uint8_t encTempBuf[CEB_BUF_SIZE] = {0, };            
+        case MENU_SPI_WRITE_ENC_DATA:               //  Master >>>>>(encrypt data)>>>>> Slave
+            
             
             pc_serial.printf("input Encrypt String (16 character) : ");
             for(int iCnt = 0 ; iCnt < 16 ; ++iCnt)                
@@ -225,14 +227,18 @@
             break;
             
             
-        case MENU_SPI_READ_ENC_DATA:     
+        case MENU_SPI_READ_ENC_DATA:                //  Master <<<<<(encrypted data)<<<<< Slave  
             int encryptWaitCnt = 10;
+            
+            // ★★★★ status reg 읽어오는 부분이 문제가 있는듯함 여기를 먼저 고쳐야함 
             while(1)
             {
                 ret = cebf746_packet_read(FUNC_READ_STATUS, 0);
-                if(ret & 0x02)       // Encrypting..
+                if(ret == 0x02)       // Encrypting..                
                 {
-                    --encryptWaitCnt;                    
+                    --encryptWaitCnt;       
+                    if(0 >= encryptWaitCnt)
+                        break;
                 }
                 else
                 {
@@ -240,14 +246,22 @@
                 }
             }
             
+            
             if(0 == encryptWaitCnt)
-            {
-                printf("[INFO] The CEBF746 is running\n");
+            {                
+                printf("[INFO] The CEBF746 is running, STATUS[%02X]\n", ret);
                 continue;
             }
             else
             {
                 /* 161019_암호화된 데이터 읽어와야함. 슬레이브도 구현 해야함 */
+                reciveData.size = sizeof(encTempBuf)+2;
+                reciveData.buf = (uint8_t*)encTempBuf;
+                reciveData.crc16 = 0;
+              
+                ret = cebf746_packet_read(FUNC_READ_ENC_DATA, &reciveData);
+                
+                printf("[DEBUF]MENU_SPI_READ_ENC_DATA return [%02X]\n", ret);
             }