Fabien Lepoutre
/
Prog_Projet
Projet3i4
Diff: ComSPI.cpp
- Revision:
- 1:bb98d7d1e25f
- Parent:
- 0:f0c9c47e4edd
diff -r f0c9c47e4edd -r bb98d7d1e25f ComSPI.cpp --- a/ComSPI.cpp Mon Apr 23 14:40:40 2012 +0000 +++ b/ComSPI.cpp Tue Apr 24 14:51:28 2012 +0000 @@ -2,35 +2,30 @@ SPI SPI_Master(p11, p12, p13); //mosi, miso, sck DigitalOut cs(p14); //Selection Slave SPISlave SPI_Slave(p5, p6, p7, p8); //mosi, miso, sck, ssel - +volatile int attente; void v_InitSPI(){ - printf("Entree dans Init \n\r"); SPI_Master.format(8,0); SPI_Master.frequency(1000000); SPI_Slave.format(8,0); - SPI_Slave.frequency(1000000); - + SPI_Slave.frequency(1000000); } void v_TestComSPI(){ - printf("Entree dans testcom \r\n"); + attente=0; v_InitSPI(); Thread tSlave(v_threadSPISlave); Thread tMaster(v_threadSPIMaster); + while(attente==0); } void v_threadSPIMaster(void const* argument){ - printf("Entree dans le thread Master \r \n"); int answer, msgsend=1; - - cs=0; answer = SPI_Master.write(msgsend); cs=1; - cout<<endl<<cs<<endl; wait_ms(100); cs=0; answer = SPI_Master.write(0x00); @@ -41,19 +36,20 @@ cs=0; answer=SPI_Master.write(TERMINATE); //send a Terminate value cs=1; - if(answer==0) printf("Communication OK \r\n)"); //Normaly Slave returns 0 : end of transmission - else printf("Probleme de communication \r\n)"); + if(answer==0) printf("Communication SPI OK \r\n)"); //Normaly Slave returns 0 : end of transmission + else printf("Probleme de communication SPI1 \r\n)"); } - printf("Sortie du thread Master \r\n"); + else{ + printf("Probleme de communication SPI2 \r\n"); + } + attente++; } void v_threadSPISlave(void const* argument){ - printf("Entree dans le thread Slave \r\n"); int rec, rec2; bool end=false; while(!end){ if(SPI_Slave.receive()) { - rec = SPI_Slave.read(); rec2=rec+5; // Read byte from master printf("Slave -> Valeur recue :%d\r\n", rec); @@ -68,12 +64,8 @@ SPI_Slave.reply(rec2); // Make this the next reply (add 5); printf("Slave -> Valeur renvoyee : %d \r\n",rec2); } - } - + } } } - printf("Sortie du thread Slave \r\n"); - - }