SPI to Ethernet Slave
Dependencies: WIZnetInterface mbed
Fork of SPI_HelloWorld_Mbed by
Revision 8:46bd5776b6ae, committed 2016-03-10
- Comitter:
- Ricky_Kwon
- Date:
- Thu Mar 10 05:21:42 2016 +0000
- Parent:
- 7:b09eade395f7
- Child:
- 9:32e3edb40824
- Commit message:
- switch case
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Mar 10 02:12:58 2016 +0000 +++ b/main.cpp Thu Mar 10 05:21:42 2016 +0000 @@ -15,8 +15,20 @@ SPISlave slave(PA_8, PA_7, PA_6, PA_5); // mosi, miso, sclk, ssel int main() { - int SpiData=0; - char EthTx[1]; + + /**(volatile uint32_t *)(0x41001014) = 0x0060100; + *(volatile uint32_t *)(0x41003000) = 0x10; + *(volatile uint32_t *)(0x41003004) = 0x10; + *(volatile uint32_t *)(0x41003008) = 0x10; + *(volatile uint32_t *)(0x41003080) = 0x10; + *(volatile uint32_t *)(0x41003098) = 0x10;*/ + + int SPI_Data=0; + int SPI_Send_Cnt=0; + int Length=0; + char Eth_Receive_Check_Flag = 1; + char EthTx[1]={0}; + char EthRx[256]={0,}; printf("SPI to Ethernet Slave\r\n"); @@ -48,6 +60,7 @@ break; } } + /* * Create Client Socket and Connecting */ @@ -63,11 +76,59 @@ while(1) { + if(Eth_Receive_Check_Flag==1) + { + printf("a"); + Length = socket.receive(EthRx, sizeof(EthRx)); + if(Length>0) + { + printf("b"); + Eth_Receive_Check_Flag = 0; + } + } if(slave.receive()) { - SpiData = slave.read(); - EthTx[0] = SpiData; - socket.send(EthTx, 1); + SPI_Data = slave.read(); + switch(SPI_Data) + { + case 0x80: + printf("c"); + if(!Eth_Receive_Check_Flag) + { + printf("d"); + slave.reply(0x80); + } + else + { + printf("e"); + slave.reply(0x87); + } + break; + case 0x81: + printf("f"); + slave.reply(Length); + break; + case 0x82: + if(SPI_Send_Cnt!=Length) + { + printf("g"); + slave.reply(EthRx[SPI_Send_Cnt]); + SPI_Send_Cnt++; + } + else + { + printf("h"); + SPI_Send_Cnt = 0; + Eth_Receive_Check_Flag = 1; + } + break; + default: + printf("i"); + EthTx[0] = SPI_Data; + socket.send(EthTx, 1); + break; + + } } } }