161007_BDK_EEPROM
Dependencies: mbed
Fork of 161006_BDK_SPImaster by
Diff: main.cpp
- Revision:
- 4:a9fa91152c17
- Parent:
- 3:c6f8271b2d4e
- Child:
- 5:47353da6bca4
diff -r c6f8271b2d4e -r a9fa91152c17 main.cpp --- a/main.cpp Wed Oct 05 07:11:05 2016 +0000 +++ b/main.cpp Wed Oct 05 08:58:51 2016 +0000 @@ -6,18 +6,27 @@ #define PRINTD(arg1,arg2...) printf(arg1,##arg2) #endif -SPI spi(PA_7,PA_6,PA_5); // MOSI, MISO, SCLK(CLK,SCK) -DigitalOut cs(PA_4); + +#define SPI_MOSI PA_7 +#define SPI_MISO PA_6 +#define SPI_SCLK PA_5 +#define SPI_SSEL PA_4 + +SPI spi_master(SPI_MOSI,SPI_MISO,SPI_SCLK); // MOSI, MISO, SCLK(CLK,SCK) +DigitalOut cs(SPI_SSEL); + +Serial pc_serial(USBTX, USBRX); + void SPI_INIT() { PRINTD("Set SPI init..\n"); PRINTD("Set SPI format..\n"); - spi.format(8,0); + spi_master.format(8,0); PRINTD("Set frequency to default..\n"); - spi.frequency(1000000); // default 1MHz + spi_master.frequency(1000000); // default 1MHz } - +/* void SPI_Write() { char temp; @@ -45,18 +54,18 @@ PRINTD("%c[%02x]",tx_buffer[i],tx_buffer[i]); } PRINTD("\n\n"); - spi.lock(); + spi_master.lock(); for(i=0;i<=tx_cnt;++i) { value=tx_buffer[i]; PRINTD("[M]write[%d]=%c[%02x]\n",i,value,value); cs=0; - response=spi.write(value); + response=spi_master.write(value); cs=-1; PRINTD("[M]receive=%c[%x]\n",response,response); rx_buffer[++rx_cnt]=response; } - spi.unlock(); + spi_master.unlock(); for(i=0;i<255;++i) { tx_buffer[i]=0; @@ -73,14 +82,81 @@ } } } +*/ + +// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ main(); int main() { + int spiTxCnt = 0; + char spiTxReadyFlag = 0; + + char serialRxBuf[255]; + int serialRxLen = 0; + + pc_serial.printf("\n\n========== KSS SPI Master [Start] ==========\n"); + + + while(1) + { + if(0 != pc_serial.readable()) // wait serial input.. + { + pc_serial.scanf("%s", serialRxBuf); + serialRxLen = strlen(serialRxBuf); + pc_serial.printf("len=[%d] %s\n", serialRxLen, serialRxBuf); + spiTxReadyFlag = 1; + } + if(1 == spiTxReadyFlag) + { + // SPI Send Start + spi_master.lock(); + cs = 0; + for(spiTxCnt = 0 ; spiTxCnt < serialRxLen + 1 ; ++spiTxCnt) + { + //printf("send Cnt[%d] [0x%02X]\n", spiTxCnt, serialRxBuf[spiTxCnt]); + spi_master.write(serialRxBuf[spiTxCnt]); + } + cs = 1; + spi_master.unlock(); + spiTxReadyFlag = 0; + } + + + + /* TODO " ----(SPI)-----> master --> serial " + + */ + + } + + + + + + + + + + + + + + + + + + + + + + +#if 0 // 161005_BDK_backup2 start int send_data; - SPI_INIT(); - + SPI_INIT(); while(1) { SPI_Write(); } +#endif // 161005_BDK_backup2 end + return 0; }