Fabien Lepoutre
/
Prog_Projet
Projet3i4
Revision 0:f0c9c47e4edd, committed 2012-04-23
- Comitter:
- fabienlepoutre
- Date:
- Mon Apr 23 14:40:40 2012 +0000
- Child:
- 1:bb98d7d1e25f
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AnalogTest.cpp Mon Apr 23 14:40:40 2012 +0000 @@ -0,0 +1,92 @@ +#include "AnalogTest.h" + +AnalogIn In15(p15); +AnalogIn In16(p16); +AnalogIn In17(p17); +AnalogOut Out18(p18); +AnalogIn In19(p19); +AnalogIn In20(p20); + +void v_TestCAN_CNA(){ + char char1 = 0; + float val=1; + int aff = 0; + cout<<"\033[2J"; + cout<<"\033[H"; + + while(char1 != 'q'){ + + + cout<<"valeur testee = "<<val<<" \n\r"; + + int result = i_TestPorts(val, aff); + aff =0; + if((result == 6)&&val<3.3){ + cout<<"Il y a "<<result<<"ports defaillants et V < 3,3V => Probleme sur Port Analog Out \r\n"; + } + + cout<<"Continuer? y / q voir valeur des ports : v \r\n"; + cin>>char1; + if(char1 == 'v'){ + aff = 1; + } + + val = val + 0.2; + if(val >= 3.3){ + val = 0; + } + + cout<<"\033[2J \n\r"; + cout<<"\033[H \n\r"; + + } +} + + +int i_TestPorts(float val, int aff){ + int ret = 0; + val = val/3.3; + Out18 = val; + + cout<<"Compte rendu du test : \r\n"; + if((In15.read() < (val-0.01))||(In15 > val + 0.01)){ + cout<<"Port p15 inexact \n\r"; + ret ++; + } + if((In16.read() < (val-0.01))||(In16 > val + 0.01)){ + cout<<"Port p16 inexact \n\r"; + ret ++; + } + + if((In17.read() < (val-0.01))||(In17 > val + 0.01)){ + cout<<"Port p17 inexact \n\r"; + ret ++; + } + + if((Out18.read() < (val-0.01))||(Out18.read() > val + 0.01)){ + cout<<"Port p18 inexact \n\r"; + ret ++; + } + + if((In19.read() < (val-0.01))||(In19 > val + 0.01)){ + cout<<"Port p19 inexact \n\r"; + ret ++; + } + + if((In20.read() < (val-0.01))||(In20 > val + 0.01)){ + cout<<"Port p20 inexact \n\r"; + ret ++; + } + if(aff ==1){ + cout<<"p15 ="<<In15.read()*3.3<<" \r\n"; + cout<<"p16 ="<<In16.read()*3.3<<" \r\n"; + cout<<"p17 ="<<In17.read()*3.3<<" \r\n"; + cout<<"p18 ="<<Out18.read()*3.3<<" \r\n"; + cout<<"p19 ="<<In19.read()*3.3<<" \r\n"; + cout<<"p20 ="<<In20.read()*3.3<<" \r\n"; + + } + + return ret; + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AnalogTest.h Mon Apr 23 14:40:40 2012 +0000 @@ -0,0 +1,7 @@ +#include "mbed.h" +#include <iostream> + + + +void v_TestCAN_CNA(); +int i_TestPorts(float val, int aff); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ComSPI.cpp Mon Apr 23 14:40:40 2012 +0000 @@ -0,0 +1,79 @@ +#include "ComSPI.h" +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 + + + +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); + +} + + +void v_TestComSPI(){ + printf("Entree dans testcom \r\n"); + v_InitSPI(); + Thread tSlave(v_threadSPISlave); + Thread tMaster(v_threadSPIMaster); +} + +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); + cs=1; + + printf("Master -> Valeur envoye :%d Valeur recu : %d \r\n", msgsend, answer); + if(answer == (msgsend+5)){ //Normaly slave returns msgsend + 5 + 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)"); + } + printf("Sortie du thread Master \r\n"); +} + +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); + if(rec!=0){ // discard the dummy buffer write + if(rec == TERMINATE) { //if terminate signal : stop kill thread + printf("Signal Termine \r\n"); + end = true; + SPI_Slave.reply(0); + } + + else{ + 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"); + + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ComSPI.h Mon Apr 23 14:40:40 2012 +0000 @@ -0,0 +1,12 @@ +#include "mbed.h" +#include <iostream> +#include "rtos.h" + +#define TERMINATE 53 + +//Fonctions de test des connections SPI + +void v_InitSPI(); +void v_TestComSPI(); +void v_threadSPISlave(void const*); +void v_threadSPIMaster(void const*);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LibTest.cpp Mon Apr 23 14:40:40 2012 +0000 @@ -0,0 +1,21 @@ +#include "LibTest.h" + + + + +int i_IntroTest(){ + int choix; + cout<<endl<<"Programme de test \r"<<endl; + + cout<<"Selectionner le test a effectuer: \n\r"; + cout<<"1. CAN / CNA \n\r"; + + cout<<"Choix : "; + cin>>choix; + cout<<choix<<"\r\n"; + + + return choix; +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LibTest.h Mon Apr 23 14:40:40 2012 +0000 @@ -0,0 +1,9 @@ +#include "mbed.h" +#include <iostream> + +#define ANALOG_IN_OUT 1 +#define SPI 2 +#define I2C 3 + +int i_IntroTest(); +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Apr 23 14:40:40 2012 +0000 @@ -0,0 +1,20 @@ +#include "mbed.h" +#include "LibTest.h" +#include "ComSPI.h" +#include "AnalogTest.h" +DigitalOut myled(LED1); + +int main() { + int choix = i_IntroTest(); + switch(choix){ + case ANALOG_IN_OUT : v_TestCAN_CNA(); + break; + case SPI: v_TestComSPI(); + break; + case I2C: + + default : break; + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Apr 23 14:40:40 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479