161010_bug fix multi byte read

Dependencies:   mbed

Fork of 161006_BDK_EEPROM by CUBEBITE

Committer:
bcup
Date:
Fri Oct 07 08:15:21 2016 +0000
Branch:
KSS
Revision:
7:45b16ef560a9
Parent:
6:21b3128fbaef
Child:
8:1921f56f6ee6
161007_BDK_EEPROM(M)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcup 0:24e90e3ca3f4 1 #include "mbed.h"
bcup 0:24e90e3ca3f4 2
bcup 0:24e90e3ca3f4 3 #define DEBUG_SPI
bcup 0:24e90e3ca3f4 4
bcup 0:24e90e3ca3f4 5 #ifdef DEBUG_SPI
bcup 0:24e90e3ca3f4 6 #define PRINTD(arg1,arg2...) printf(arg1,##arg2)
bcup 0:24e90e3ca3f4 7 #endif
bcup 0:24e90e3ca3f4 8
gandol2 3:4bb95aa46ebc 9
gandol2 3:4bb95aa46ebc 10 #define SPI_MOSI PA_7
gandol2 3:4bb95aa46ebc 11 #define SPI_MISO PA_6
gandol2 3:4bb95aa46ebc 12 #define SPI_SCLK PA_5
gandol2 3:4bb95aa46ebc 13 #define SPI_SSEL PA_4
gandol2 3:4bb95aa46ebc 14
gandol2 6:21b3128fbaef 15 #define EEPROM_WREN 0x06 // Write Enable
gandol2 6:21b3128fbaef 16 #define EEPROM_WRDI 0x04 // Write Disable
gandol2 6:21b3128fbaef 17 #define EEPROM_RDSR 0x05 // Read Status Register
gandol2 6:21b3128fbaef 18 #define EEPROM_WRSR 0x01 // Write Status Register
gandol2 6:21b3128fbaef 19 #define EEPROM_READ 0x03 // Read EEPROM Memory
gandol2 6:21b3128fbaef 20 #define EEPROM_WRITE 0x02 // Write EEPROM Memory
bcup 7:45b16ef560a9 21 #define EEPROM_MULTIREAD 0x07 // Read Multibyte EEPROM Memory
gandol2 3:4bb95aa46ebc 22
gandol2 3:4bb95aa46ebc 23 SPISlave spi_slave(SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_SSEL); // MOSI, MISO, SCLK(CLK), SSEL(CS)=NC
gandol2 3:4bb95aa46ebc 24 Serial pc_serial(USBTX, USBRX);
bcup 0:24e90e3ca3f4 25
bcup 2:5311ad7c83e6 26 void SPI_SlaveInit()
bcup 0:24e90e3ca3f4 27 {
bcup 2:5311ad7c83e6 28 PRINTD("Set the SPI SLAVE format\n");
gandol2 3:4bb95aa46ebc 29 spi_slave.format(8,0); // setup 8bit 0 mode
bcup 2:5311ad7c83e6 30 PRINTD("Set the SPI SLAVE frequency\n");
bcup 7:45b16ef560a9 31 //spi_slave.frequency(50000000); // default 1MHz
bcup 7:45b16ef560a9 32 spi_slave.frequency(1000000);
bcup 0:24e90e3ca3f4 33 }
bcup 0:24e90e3ca3f4 34
bcup 2:5311ad7c83e6 35 void SPI_SlaveWrite()
bcup 0:24e90e3ca3f4 36 {
bcup 2:5311ad7c83e6 37 char tx_buffer[255]={0};
bcup 2:5311ad7c83e6 38 char reply;
bcup 2:5311ad7c83e6 39 char i;
bcup 1:3a338e553a54 40 char temp;
bcup 2:5311ad7c83e6 41 char tx_cnt = 0;
bcup 2:5311ad7c83e6 42 int value;
bcup 2:5311ad7c83e6 43 PRINTD("Input Strging=");
bcup 0:24e90e3ca3f4 44 while(1)
bcup 0:24e90e3ca3f4 45 {
bcup 0:24e90e3ca3f4 46
bcup 0:24e90e3ca3f4 47 temp=getchar();
bcup 2:5311ad7c83e6 48 tx_buffer[tx_cnt++]=temp;
bcup 0:24e90e3ca3f4 49 if(temp==0x0d)
bcup 0:24e90e3ca3f4 50 {
bcup 0:24e90e3ca3f4 51 tx_buffer[tx_cnt]=0;
bcup 0:24e90e3ca3f4 52 PRINTD("\nData send Finish...\n");
bcup 0:24e90e3ca3f4 53 for(i=0;i<=tx_cnt;++i)
bcup 0:24e90e3ca3f4 54 {
bcup 0:24e90e3ca3f4 55 PRINTD("%c[%02x]",tx_buffer[i],tx_buffer[i]);
bcup 0:24e90e3ca3f4 56 }
bcup 0:24e90e3ca3f4 57 PRINTD("\n\n");
bcup 0:24e90e3ca3f4 58 for(i=0;i<=tx_cnt;++i)
bcup 0:24e90e3ca3f4 59 {
bcup 0:24e90e3ca3f4 60 value=tx_buffer[i];
bcup 2:5311ad7c83e6 61 PRINTD("write[%d]=%c[%02x]\n",i,value,value);
gandol2 3:4bb95aa46ebc 62 spi_slave.reply(value);
bcup 0:24e90e3ca3f4 63 }
bcup 2:5311ad7c83e6 64 for(i=0;i<tx_cnt;++i)
bcup 0:24e90e3ca3f4 65 {
bcup 0:24e90e3ca3f4 66 tx_buffer[i]=0;
bcup 2:5311ad7c83e6 67 PRINTD("init_tx_buf[%d]=%c\n",i,tx_buffer[i]);
bcup 0:24e90e3ca3f4 68 }
bcup 2:5311ad7c83e6 69 tx_cnt=0;
bcup 2:5311ad7c83e6 70 PRINTD("break\n");
bcup 2:5311ad7c83e6 71 break;
bcup 0:24e90e3ca3f4 72 }
bcup 0:24e90e3ca3f4 73 else
bcup 0:24e90e3ca3f4 74 {
bcup 0:24e90e3ca3f4 75 PRINTD("%c[%02x]",tx_buffer[tx_cnt],tx_buffer[tx_cnt]);
bcup 0:24e90e3ca3f4 76 }
bcup 0:24e90e3ca3f4 77 }
bcup 2:5311ad7c83e6 78 return;
bcup 0:24e90e3ca3f4 79 }
bcup 0:24e90e3ca3f4 80
gandol2 6:21b3128fbaef 81 void spi_dummy_reply(void)
gandol2 6:21b3128fbaef 82 {
gandol2 6:21b3128fbaef 83 spi_slave.reply( 0xA0 );
gandol2 6:21b3128fbaef 84 }
gandol2 6:21b3128fbaef 85
gandol2 6:21b3128fbaef 86 #define EEPROM_SIZE 256
gandol2 6:21b3128fbaef 87 char statusReg;
gandol2 6:21b3128fbaef 88 char eepBuf[EEPROM_SIZE];
gandol2 6:21b3128fbaef 89
gandol2 6:21b3128fbaef 90 void printBuf(char * buf, int length)
gandol2 6:21b3128fbaef 91 {
gandol2 6:21b3128fbaef 92 pc_serial.printf("=======================[EEPROM]========================\n");
gandol2 6:21b3128fbaef 93 pc_serial.printf(" |");
gandol2 6:21b3128fbaef 94 for(int iCnt = 0 ; iCnt < 16 ; ++iCnt)
gandol2 6:21b3128fbaef 95 {
gandol2 6:21b3128fbaef 96 pc_serial.printf("%02X|", iCnt);
gandol2 6:21b3128fbaef 97 }
gandol2 6:21b3128fbaef 98 pc_serial.printf("\n");
gandol2 6:21b3128fbaef 99
gandol2 6:21b3128fbaef 100
gandol2 6:21b3128fbaef 101 for(int iCnt = 0 ; iCnt < length ; ++iCnt)
gandol2 6:21b3128fbaef 102 {
gandol2 6:21b3128fbaef 103 if(0 == ((iCnt) % 16))
gandol2 6:21b3128fbaef 104 {
gandol2 6:21b3128fbaef 105 pc_serial.printf("[0x%02X] ", iCnt);
gandol2 6:21b3128fbaef 106 }
gandol2 6:21b3128fbaef 107
gandol2 6:21b3128fbaef 108 pc_serial.printf("%02X ", *(buf + iCnt));
gandol2 6:21b3128fbaef 109
gandol2 6:21b3128fbaef 110 if(0 == ((iCnt+1) % 16))
gandol2 6:21b3128fbaef 111 {
gandol2 6:21b3128fbaef 112 pc_serial.printf("\n");
gandol2 6:21b3128fbaef 113
gandol2 6:21b3128fbaef 114 }
gandol2 6:21b3128fbaef 115
gandol2 6:21b3128fbaef 116 }
gandol2 6:21b3128fbaef 117 pc_serial.printf("=======================================================\n");
gandol2 6:21b3128fbaef 118 }
gandol2 6:21b3128fbaef 119
bcup 0:24e90e3ca3f4 120 int main()
bcup 0:24e90e3ca3f4 121 {
gandol2 6:21b3128fbaef 122
bcup 7:45b16ef560a9 123 char spiMulti = 0;
bcup 7:45b16ef560a9 124 char eepAddr = 0;
bcup 7:45b16ef560a9 125 char eepData = 0;
bcup 7:45b16ef560a9 126
gandol2 3:4bb95aa46ebc 127 char serialTxReadyFlag = 0;
gandol2 3:4bb95aa46ebc 128 int spiRxTempBuf = 0;
gandol2 3:4bb95aa46ebc 129 char spiRxBuf[255];
gandol2 3:4bb95aa46ebc 130 int spiRxTempCnt = 0;
gandol2 3:4bb95aa46ebc 131 int spiRxLen = 0;
gandol2 3:4bb95aa46ebc 132
gandol2 3:4bb95aa46ebc 133
gandol2 3:4bb95aa46ebc 134 int spiTxCnt = 0;
gandol2 3:4bb95aa46ebc 135 char spiTxReadyFlag = 0;
gandol2 3:4bb95aa46ebc 136
gandol2 3:4bb95aa46ebc 137 char serialRxBuf[255];
gandol2 3:4bb95aa46ebc 138 int serialRxLen = 0;
gandol2 3:4bb95aa46ebc 139
gandol2 3:4bb95aa46ebc 140 SPI_SlaveInit();
gandol2 6:21b3128fbaef 141
bcup 7:45b16ef560a9 142 /*
gandol2 6:21b3128fbaef 143 NVIC_SetVector( SPI_IRQn , ( uint32_t ) executa_spi_slave_hw ) ;
gandol2 6:21b3128fbaef 144 NVIC_SetPriority( SPI_IRQn , 2 ) ;
gandol2 6:21b3128fbaef 145 NVIC_EnableIRQ( SPI_IRQn ) ;
bcup 7:45b16ef560a9 146 */
gandol2 3:4bb95aa46ebc 147
gandol2 3:4bb95aa46ebc 148
gandol2 5:1ccdbfe5e4bb 149 pc_serial.printf("\n\n========== KSS SPI Slave2 [Start] ==========\n");
gandol2 3:4bb95aa46ebc 150
gandol2 3:4bb95aa46ebc 151 while(1)
gandol2 3:4bb95aa46ebc 152 {
gandol2 3:4bb95aa46ebc 153 if(spi_slave.receive()) // wait SPI data input...
gandol2 3:4bb95aa46ebc 154 {
gandol2 3:4bb95aa46ebc 155 spiRxTempBuf = spi_slave.read();
gandol2 6:21b3128fbaef 156 //spi_slave.reply( statusReg++ );
gandol2 6:21b3128fbaef 157 //continue;
gandol2 6:21b3128fbaef 158
gandol2 6:21b3128fbaef 159 switch(spiRxTempBuf)
gandol2 6:21b3128fbaef 160 {
gandol2 6:21b3128fbaef 161 case EEPROM_WREN:
gandol2 6:21b3128fbaef 162 //spi_dummy_reply();
gandol2 6:21b3128fbaef 163 pc_serial.printf("[INFO] SPI_MOSI(RX) : WREN\n");
gandol2 6:21b3128fbaef 164 statusReg = statusReg | (1<<1) ;
gandol2 6:21b3128fbaef 165 pc_serial.printf("[INFO] WREN sucess [0x%02X]\n", statusReg);
gandol2 6:21b3128fbaef 166 break;
gandol2 6:21b3128fbaef 167
gandol2 6:21b3128fbaef 168 case EEPROM_WRDI:
gandol2 6:21b3128fbaef 169 //spi_dummy_reply();
gandol2 6:21b3128fbaef 170 pc_serial.printf("[INFO] SPI_MOSI(RX) : WRDI\n");
gandol2 6:21b3128fbaef 171 statusReg = statusReg & (~(1 << 1)) ;
gandol2 6:21b3128fbaef 172 pc_serial.printf("[INFO] WRDI sucess [0x%02X]\n", statusReg);
gandol2 6:21b3128fbaef 173 break;
gandol2 6:21b3128fbaef 174
gandol2 6:21b3128fbaef 175 case EEPROM_RDSR:
gandol2 6:21b3128fbaef 176 spi_slave.reply( statusReg );
gandol2 6:21b3128fbaef 177 pc_serial.printf("[INFO] SPI_MOSI(RX) : RDSR\n");
gandol2 6:21b3128fbaef 178 pc_serial.printf("[INFO] SPI_MISO(TX) : RDSR[0x%02X] \n", statusReg);
gandol2 6:21b3128fbaef 179 break;
gandol2 6:21b3128fbaef 180
gandol2 6:21b3128fbaef 181
gandol2 6:21b3128fbaef 182 case EEPROM_WRITE:
gandol2 6:21b3128fbaef 183 // EEPROM Address read..
gandol2 6:21b3128fbaef 184 while(!spi_slave.receive());
gandol2 6:21b3128fbaef 185 eepAddr = spi_slave.read();
gandol2 6:21b3128fbaef 186
gandol2 6:21b3128fbaef 187 // EEPROM Data read..
gandol2 6:21b3128fbaef 188 while(!spi_slave.receive());
gandol2 6:21b3128fbaef 189 eepData = spi_slave.read();
gandol2 6:21b3128fbaef 190
gandol2 6:21b3128fbaef 191 pc_serial.printf("\n[DEBUG] Addr[0x%02X] Data[0x%02X] \n", eepAddr, eepData);
gandol2 6:21b3128fbaef 192
gandol2 6:21b3128fbaef 193 if(statusReg & 0x02)
gandol2 6:21b3128fbaef 194 {
gandol2 6:21b3128fbaef 195 statusReg |= 0x01;
gandol2 6:21b3128fbaef 196 eepBuf[eepAddr] = eepData;
gandol2 6:21b3128fbaef 197 printBuf(eepBuf, EEPROM_SIZE);
gandol2 6:21b3128fbaef 198 statusReg &= (~0x01);
gandol2 6:21b3128fbaef 199
gandol2 6:21b3128fbaef 200 }
gandol2 6:21b3128fbaef 201 else
gandol2 6:21b3128fbaef 202 {
gandol2 6:21b3128fbaef 203 pc_serial.printf("\nwrite command is disabled\n");
gandol2 6:21b3128fbaef 204 }
gandol2 6:21b3128fbaef 205 break;
gandol2 6:21b3128fbaef 206
gandol2 6:21b3128fbaef 207
gandol2 6:21b3128fbaef 208 case EEPROM_READ:
gandol2 6:21b3128fbaef 209 // EEPROM Address read..
gandol2 6:21b3128fbaef 210 while(!spi_slave.receive());
gandol2 6:21b3128fbaef 211 eepAddr = spi_slave.read();
gandol2 6:21b3128fbaef 212
gandol2 6:21b3128fbaef 213 spi_slave.reply( eepBuf[eepAddr] );
gandol2 6:21b3128fbaef 214
gandol2 6:21b3128fbaef 215 pc_serial.printf("\n[DEBUG] Addr[0x%02X]\n", eepAddr);
gandol2 6:21b3128fbaef 216
gandol2 6:21b3128fbaef 217
gandol2 6:21b3128fbaef 218
gandol2 6:21b3128fbaef 219
gandol2 6:21b3128fbaef 220 break;
gandol2 6:21b3128fbaef 221
gandol2 6:21b3128fbaef 222
bcup 7:45b16ef560a9 223 case EEPROM_MULTIREAD:
bcup 7:45b16ef560a9 224 // EEPROM_MULTIREAD..
bcup 7:45b16ef560a9 225 while(!spi_slave.receive());
bcup 7:45b16ef560a9 226 eepAddr = spi_slave.read();
bcup 7:45b16ef560a9 227 printf("[DEBUG] [M to S] eepAddr=0x%02x\n",eepAddr++);
bcup 7:45b16ef560a9 228 //printf("[DEBUG] [M to S] eepAddr=0x%02x\n",eepAddr);
bcup 7:45b16ef560a9 229 for(int i=0;i<7;i++)
bcup 7:45b16ef560a9 230 {
bcup 7:45b16ef560a9 231 //spi_slave.reply( eepBuf[eepAddr] );
bcup 7:45b16ef560a9 232 spi_slave.reply( i );
bcup 7:45b16ef560a9 233 //++eepAddr;
bcup 7:45b16ef560a9 234 //printf("[0x%02x] ",spiMulti);
bcup 7:45b16ef560a9 235 pc_serial.printf(".");
bcup 7:45b16ef560a9 236
bcup 7:45b16ef560a9 237 }
bcup 7:45b16ef560a9 238 pc_serial.printf("\n");
bcup 7:45b16ef560a9 239 break;
bcup 7:45b16ef560a9 240
bcup 7:45b16ef560a9 241
gandol2 6:21b3128fbaef 242 default:
gandol2 6:21b3128fbaef 243 //spi_dummy_reply();
gandol2 6:21b3128fbaef 244 }
gandol2 6:21b3128fbaef 245
gandol2 6:21b3128fbaef 246 //pc_serial.printf("------------------------ end SPI Communication\n");
gandol2 6:21b3128fbaef 247
gandol2 6:21b3128fbaef 248 }
gandol2 6:21b3128fbaef 249 }
gandol2 6:21b3128fbaef 250
gandol2 6:21b3128fbaef 251
gandol2 6:21b3128fbaef 252
gandol2 6:21b3128fbaef 253
gandol2 6:21b3128fbaef 254
gandol2 6:21b3128fbaef 255
gandol2 6:21b3128fbaef 256
gandol2 6:21b3128fbaef 257
gandol2 6:21b3128fbaef 258
gandol2 6:21b3128fbaef 259
gandol2 6:21b3128fbaef 260 /*
gandol2 3:4bb95aa46ebc 261 spiRxBuf[spiRxTempCnt++] = spiRxTempBuf;
gandol2 3:4bb95aa46ebc 262
gandol2 3:4bb95aa46ebc 263 if(0x00 == spiRxTempBuf)
gandol2 3:4bb95aa46ebc 264 {
gandol2 3:4bb95aa46ebc 265 serialTxReadyFlag = 1;
gandol2 3:4bb95aa46ebc 266 //pc_serial.printf("SPI Recive Byte [%d]\n", spiRxTempCnt-1);
gandol2 3:4bb95aa46ebc 267 spiRxLen = strlen(spiRxBuf);
gandol2 3:4bb95aa46ebc 268 spiRxTempCnt = 0;
gandol2 3:4bb95aa46ebc 269 }
gandol2 6:21b3128fbaef 270
gandol2 3:4bb95aa46ebc 271 }
gandol2 3:4bb95aa46ebc 272 if(1 == serialTxReadyFlag)
gandol2 3:4bb95aa46ebc 273 {
gandol2 3:4bb95aa46ebc 274 serialTxReadyFlag = 0;
gandol2 6:21b3128fbaef 275 pc_serial.printf("SPI_RX Data : len=[%d] %s\n", spiRxLen, spiRxBuf);
gandol2 3:4bb95aa46ebc 276 }
gandol2 3:4bb95aa46ebc 277
gandol2 6:21b3128fbaef 278 */
gandol2 6:21b3128fbaef 279
gandol2 3:4bb95aa46ebc 280
gandol2 3:4bb95aa46ebc 281
gandol2 6:21b3128fbaef 282 #if 0
bcup 4:cc97d7a33efc 283 /* TODO "serial -> slave ----(SPI)-----> " */
gandol2 3:4bb95aa46ebc 284
gandol2 3:4bb95aa46ebc 285 if(0 != pc_serial.readable()) // wait serial input..
gandol2 3:4bb95aa46ebc 286 {
gandol2 3:4bb95aa46ebc 287 pc_serial.scanf("%s", serialRxBuf);
gandol2 3:4bb95aa46ebc 288 serialRxLen = strlen(serialRxBuf);
gandol2 3:4bb95aa46ebc 289 pc_serial.printf("len=[%d] %s\n", serialRxLen, serialRxBuf);
gandol2 3:4bb95aa46ebc 290 spiTxReadyFlag = 1;
gandol2 3:4bb95aa46ebc 291 }
gandol2 3:4bb95aa46ebc 292 if(1 == spiTxReadyFlag)
gandol2 3:4bb95aa46ebc 293 {
bcup 4:cc97d7a33efc 294 PRINTD("spiTxReadyFlag=%d\n",spiTxReadyFlag);
gandol2 3:4bb95aa46ebc 295 // SPI Send Start
gandol2 3:4bb95aa46ebc 296
gandol2 6:21b3128fbaef 297
gandol2 3:4bb95aa46ebc 298 for(spiTxCnt = 0 ; spiTxCnt < serialRxLen + 1 ; ++spiTxCnt)
gandol2 3:4bb95aa46ebc 299 {
gandol2 3:4bb95aa46ebc 300 //printf("send Cnt[%d] [0x%02X]\n", spiTxCnt, serialRxBuf[spiTxCnt]);
gandol2 3:4bb95aa46ebc 301 spi_slave.reply(serialRxBuf[spiTxCnt]);
bcup 4:cc97d7a33efc 302 }
gandol2 6:21b3128fbaef 303
bcup 4:cc97d7a33efc 304 for(spiTxCnt = 0 ; spiTxCnt < 1 ; ++spiTxCnt)
bcup 4:cc97d7a33efc 305 {
bcup 4:cc97d7a33efc 306 //printf("send Cnt[%d] [0x%02X]\n", spiTxCnt, serialRxBuf[spiTxCnt]);
bcup 4:cc97d7a33efc 307
bcup 4:cc97d7a33efc 308 spi_slave.reply(serialRxBuf[spiTxCnt]);
bcup 4:cc97d7a33efc 309 PRINTD("reply=%c\n",serialRxBuf[spiTxCnt]);
bcup 4:cc97d7a33efc 310 }
gandol2 3:4bb95aa46ebc 311
gandol2 3:4bb95aa46ebc 312
gandol2 3:4bb95aa46ebc 313 spiTxReadyFlag = 0;
bcup 4:cc97d7a33efc 314 PRINTD("spiTxReadyFlag =0\n");
gandol2 3:4bb95aa46ebc 315 }
gandol2 6:21b3128fbaef 316 #endif
bcup 4:cc97d7a33efc 317
gandol2 3:4bb95aa46ebc 318
gandol2 3:4bb95aa46ebc 319
gandol2 3:4bb95aa46ebc 320
gandol2 3:4bb95aa46ebc 321
gandol2 3:4bb95aa46ebc 322 #if 0 // 161005_BDK_slave backup start
bcup 2:5311ad7c83e6 323 int i;
bcup 2:5311ad7c83e6 324 char valueFromMaster;
bcup 2:5311ad7c83e6 325 char rx_buffer[255]={0};
bcup 2:5311ad7c83e6 326 char rx_cnt = -1;
bcup 2:5311ad7c83e6 327 PRINTD("\n=========SLAVE=========\n");
bcup 2:5311ad7c83e6 328 SPI_SlaveInit();
bcup 2:5311ad7c83e6 329
bcup 0:24e90e3ca3f4 330 while(1)
bcup 0:24e90e3ca3f4 331 {
bcup 2:5311ad7c83e6 332
gandol2 3:4bb95aa46ebc 333 if(spi_slave.receive())
bcup 2:5311ad7c83e6 334 {
bcup 2:5311ad7c83e6 335 PRINTD("----1\n");
bcup 2:5311ad7c83e6 336 if(pc.readable())
bcup 2:5311ad7c83e6 337 {
bcup 2:5311ad7c83e6 338 SPI_SlaveWrite();
bcup 2:5311ad7c83e6 339 }
bcup 2:5311ad7c83e6 340 PRINTD("----2\n");
gandol2 3:4bb95aa46ebc 341 valueFromMaster = spi_slave.read();
bcup 2:5311ad7c83e6 342 PRINTD("----3\n");
bcup 2:5311ad7c83e6 343 //PRINTD("valueFromMaster=");
bcup 2:5311ad7c83e6 344 //PRINTD("[%c]%x\n",valueFromMaster,valueFromMaster);
bcup 2:5311ad7c83e6 345 rx_buffer[++rx_cnt]=valueFromMaster;
bcup 2:5311ad7c83e6 346 if(valueFromMaster==0)
bcup 2:5311ad7c83e6 347 {
bcup 2:5311ad7c83e6 348 PRINTD("rx_string=");
bcup 2:5311ad7c83e6 349 for(i=0;i<rx_cnt;i++)
bcup 2:5311ad7c83e6 350 {
bcup 2:5311ad7c83e6 351 PRINTD("%c",rx_buffer[i]);
bcup 2:5311ad7c83e6 352 }
bcup 2:5311ad7c83e6 353 PRINTD("\n");
bcup 2:5311ad7c83e6 354 for(i=0;i<=rx_cnt;i++)
bcup 2:5311ad7c83e6 355 {
bcup 2:5311ad7c83e6 356 rx_buffer[i]=0;
bcup 2:5311ad7c83e6 357 PRINTD("Init_rx_buf[%d]=%c\n",i,rx_buffer[i]);
bcup 2:5311ad7c83e6 358 }
bcup 2:5311ad7c83e6 359 rx_cnt=-1;
bcup 2:5311ad7c83e6 360
bcup 2:5311ad7c83e6 361 }//valueFromMaster if
bcup 2:5311ad7c83e6 362
gandol2 3:4bb95aa46ebc 363 }// spi_slave.receive() if
bcup 2:5311ad7c83e6 364 /*
bcup 2:5311ad7c83e6 365
bcup 2:5311ad7c83e6 366 */
bcup 2:5311ad7c83e6 367 }//end of while
gandol2 3:4bb95aa46ebc 368 #endif // 161005_BDK_slave backup end
bcup 2:5311ad7c83e6 369 }//end of main