Daisuke Yanagihara
/
ref_BBMv2_eps
v2 VAver
Revision 2:2e5c85275706, committed 2021-01-08
- Comitter:
- Yanagihara
- Date:
- Fri Jan 08 08:02:37 2021 +0000
- Parent:
- 1:6dd6e4386a7e
- Commit message:
- v3
Changed in this revision
spi_slave.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/spi_slave.cpp Thu Jan 07 10:23:02 2021 +0000 +++ b/spi_slave.cpp Fri Jan 08 08:02:37 2021 +0000 @@ -1,50 +1,53 @@ #include "mbed.h" -#include "mcp3208.h" - SPISlave to_cdh(p5,p6,p7,p8); // mosi, miso, sclk, ssel Serial pc(USBTX,USBRX); - /*DigitalOut myleds[4] = {LED1,LED2,LED3,LED4}; // mbed動作目視確認用LED DigitalOut ADC_on(p21); // ADC用のスイッチをONにするピン DigitalOut ADC_off(p22); // ADC用のスイッチをOFFにするピン DigitalOut COM_on(p23); DigitalOut COM_off(p24); DigitalOut myled(LED1); - + AnalogIn v(p16); SPI spi(p11,p12,p13); MCP3208 mcp3208(spi,p14); DigitalOut dyn(p25);*/ - + /*float v_bat[5], EPS_cur[5], ADC_cur[5], dyn_cur[5]; int data;*/ int main() { pc.printf("--Hi,this is eps(slave).\r\n"); - to_cdh.format(8,0); + to_cdh.format(8,3); to_cdh.frequency(1000000); - int sdummy = 0xAA; - to_cdh.reply(sdummy); + + int sdummy = 0x0F; + to_cdh.reply(sdummy); // set dummy data (通信前に事前にセット) + while(1) { if(to_cdh.receive()) { int rcmd = to_cdh.read(); + if(rcmd == 0x01){ - int sdata = 0x10; + int sdata = 0x99; to_cdh.reply(sdata); pc.printf("rcmd: %02x, ",rcmd); + pc.printf("send data: %02x\r\n",sdata); } - if(rcmd == 0x02){ + + // 2byte data + else if(rcmd == 0x02){ int sdata1 = 0x21; int sdata2 = 0x22; to_cdh.reply(sdata1); to_cdh.reply(sdata2); pc.printf("rcmd: %02x, ",rcmd); + pc.printf("send data: %02x, %02x\r\n",sdata1,sdata2); } - if(rcmd == 0x00){ + else if(rcmd == 0xFF){ to_cdh.reply(sdummy); - pc.printf("dummy: %02x\r\n",rcmd); } } }