sentral tester

Dependencies:   mbed

Committer:
awmiller
Date:
Fri May 20 17:23:07 2016 +0000
Revision:
1:29e57acc058b
Parent:
0:6834f1402927
sentral tester

Who changed what in which revision?

UserRevisionLine numberNew contents of line
awmiller 0:6834f1402927 1 //STM32 Tracler ports
awmiller 0:6834f1402927 2 #include "mbed.h"
awmiller 0:6834f1402927 3
awmiller 0:6834f1402927 4 #define SENTRAL_DI02
awmiller 0:6834f1402927 5
awmiller 0:6834f1402927 6 #define TRUE 1
awmiller 0:6834f1402927 7 #define FALSE !TRUE
awmiller 0:6834f1402927 8
awmiller 0:6834f1402927 9 #include "Sentral.h"
awmiller 0:6834f1402927 10
awmiller 0:6834f1402927 11
awmiller 0:6834f1402927 12 DigitalOut SentralPower(p20);
awmiller 0:6834f1402927 13 DigitalOut SA0(p21);
awmiller 0:6834f1402927 14
awmiller 0:6834f1402927 15 int Set_SA0(int val){
awmiller 0:6834f1402927 16
awmiller 0:6834f1402927 17 SA0 = (int)(val > 0);
awmiller 0:6834f1402927 18 return SA0;
awmiller 0:6834f1402927 19 }
awmiller 0:6834f1402927 20
awmiller 0:6834f1402927 21 int Sentral_Power(int val){
awmiller 0:6834f1402927 22
awmiller 0:6834f1402927 23 SentralPower = (int)(val > 0);
awmiller 0:6834f1402927 24 return SentralPower;
awmiller 0:6834f1402927 25 }
awmiller 0:6834f1402927 26
awmiller 0:6834f1402927 27 void Sentral_Reset(){
awmiller 0:6834f1402927 28
awmiller 0:6834f1402927 29 Sentral_Power(0);
awmiller 0:6834f1402927 30 wait(1);
awmiller 0:6834f1402927 31 Sentral_Power(1);
awmiller 0:6834f1402927 32
awmiller 0:6834f1402927 33 }
awmiller 0:6834f1402927 34
awmiller 0:6834f1402927 35
awmiller 0:6834f1402927 36 //I2C master(p28, p27);
awmiller 0:6834f1402927 37 //Serial pc(USBTX,USBRX);
awmiller 0:6834f1402927 38
awmiller 0:6834f1402927 39 /*******************************************************************************
awmiller 0:6834f1402927 40 * Function Name : SentralSetup
awmiller 0:6834f1402927 41 * Description : code snippet for setting up sentral
awmiller 0:6834f1402927 42 * to run.
awmiller 0:6834f1402927 43 * Return : None
awmiller 0:6834f1402927 44 *******************************************************************************/
awmiller 0:6834f1402927 45 unsigned int SentralSetup(Serial &pc,I2C &master){
awmiller 0:6834f1402927 46
awmiller 0:6834f1402927 47
awmiller 0:6834f1402927 48 Sentral_Reset();
awmiller 0:6834f1402927 49
awmiller 0:6834f1402927 50 unsigned char /*temp[1],*/boot_timeout=0,count=0x00;
awmiller 0:6834f1402927 51 //unsigned char test = 0, ReturnedByte=0x00;
awmiller 0:6834f1402927 52 //int ret_status= 0x00;
awmiller 0:6834f1402927 53
awmiller 0:6834f1402927 54 char cmd[10];
awmiller 0:6834f1402927 55
awmiller 0:6834f1402927 56
awmiller 0:6834f1402927 57 //Serial_PutString("Sentral Reset Reg", 20);
awmiller 0:6834f1402927 58 cmd[0] = RESET_REQ_REG;
awmiller 0:6834f1402927 59 cmd[1]=0x01;
awmiller 0:6834f1402927 60 int check = master.write(SENTRAL_ADDRESS,cmd,2);
awmiller 0:6834f1402927 61
awmiller 0:6834f1402927 62 cmd[0] = 0;
awmiller 0:6834f1402927 63
awmiller 0:6834f1402927 64 if(check)
awmiller 0:6834f1402927 65 pc.printf("I2C Reset Request Fail, Check pull-ups and Reset \r\n",check);
awmiller 0:6834f1402927 66 else
awmiller 0:6834f1402927 67 pc.printf("Reset Request Pass \r\n");
awmiller 0:6834f1402927 68
awmiller 0:6834f1402927 69 pc.printf("Status Check: ");
awmiller 0:6834f1402927 70 //while(((ReturnedByte & 0x06) != 2)&&(boot_timeout==0)){
awmiller 0:6834f1402927 71 while(((cmd[0] & 0x06) != 2)&&(boot_timeout==0)){
awmiller 0:6834f1402927 72
awmiller 0:6834f1402927 73 //test=SentralRead(SENTRAL_STATUS_REG,&ReturnedByte);
awmiller 0:6834f1402927 74 cmd[0] = SENTRAL_STATUS_REG;
awmiller 0:6834f1402927 75 //cmd[1]= 0x01;
awmiller 0:6834f1402927 76 check = master.write(SENTRAL_ADDRESS, cmd, 1);
awmiller 0:6834f1402927 77 if(check)
awmiller 0:6834f1402927 78 pc.printf("i2c write fail %d \r\n",check);
awmiller 0:6834f1402927 79 cmd[0] = 0;
awmiller 0:6834f1402927 80 master.read(SENTRAL_ADDRESS, cmd, 1);
awmiller 0:6834f1402927 81 if(check)
awmiller 0:6834f1402927 82 pc.printf("i2c read fail %d \r\n",check);
awmiller 0:6834f1402927 83
awmiller 0:6834f1402927 84 //pc.printf(" %d,%X",count,cmd[0]);
awmiller 0:6834f1402927 85
awmiller 0:6834f1402927 86 count++;
awmiller 0:6834f1402927 87 if(count==30)
awmiller 0:6834f1402927 88 boot_timeout=1;
awmiller 0:6834f1402927 89
awmiller 0:6834f1402927 90 wait_ms(100);
awmiller 0:6834f1402927 91
awmiller 0:6834f1402927 92 }
awmiller 0:6834f1402927 93
awmiller 0:6834f1402927 94 if(boot_timeout){
awmiller 0:6834f1402927 95 //PrintChars("Timeout occured, sentral not present or took too long to boot from the EEPROM\n\r");
awmiller 0:6834f1402927 96 pc.printf("Timeout occured, sentral not present or took too long to boot from the EEPROM\n\r");
awmiller 0:6834f1402927 97
awmiller 0:6834f1402927 98 //SerialPutChars("ReturnByte: 0x");
awmiller 0:6834f1402927 99 pc.printf("Timeout ReturnByte: %X \r\n", cmd[0]);
awmiller 0:6834f1402927 100 //char testbuff[5];
awmiller 0:6834f1402927 101 //snprintf(testbuff, 5, "%x,", ReturnedByte);
awmiller 0:6834f1402927 102 //SerialPutString(testbuff,5);
awmiller 0:6834f1402927 103 //SerialPutChars("Force it");
awmiller 0:6834f1402927 104 //SerialPutChar('\n');
awmiller 0:6834f1402927 105 //SerialPutChar('\r');
awmiller 0:6834f1402927 106
awmiller 0:6834f1402927 107 return RETURN_FAILURE;
awmiller 0:6834f1402927 108 }
awmiller 0:6834f1402927 109
awmiller 0:6834f1402927 110 pc.printf("Success ReturnByte: %X \r\n", cmd[0]);
awmiller 0:6834f1402927 111 // SerialPutChars("ReturnByte: 0x");
awmiller 0:6834f1402927 112 // char testbuff[5];
awmiller 0:6834f1402927 113 // snprintf(testbuff, 5, "%x,", ReturnedByte);
awmiller 0:6834f1402927 114 // SerialPutString(testbuff,5);
awmiller 0:6834f1402927 115 // //SerialPutChars("Force it");
awmiller 0:6834f1402927 116 // SerialPutChar('\n');
awmiller 0:6834f1402927 117 // SerialPutChar('\r');
awmiller 0:6834f1402927 118
awmiller 0:6834f1402927 119 //force a times out after 3 seconds
awmiller 0:6834f1402927 120 //count = 0;
awmiller 0:6834f1402927 121 //boot_timeout = FALSE;
awmiller 0:6834f1402927 122 //while(boot_timeout==FALSE){
awmiller 0:6834f1402927 123 //count++;
awmiller 0:6834f1402927 124 //if(count==30)
awmiller 0:6834f1402927 125 // boot_timeout=TRUE;
awmiller 0:6834f1402927 126
awmiller 0:6834f1402927 127 wait(1);
awmiller 0:6834f1402927 128 //}
awmiller 0:6834f1402927 129
awmiller 0:6834f1402927 130
awmiller 0:6834f1402927 131 //SentralWrite(ENABLE_EVENTS_REG,0x20); // enable gyro event only (for data logging function)
awmiller 0:6834f1402927 132 //SentralWrite(MAG_RATE_REG,0x64); //set mag rate
awmiller 0:6834f1402927 133 //SentralWrite(ACCEL_RATE_REG,0x0a); //set accel rate
awmiller 0:6834f1402927 134 //SentralWrite(GYRO_RATE_REG,0x46); //set gyro rate
awmiller 0:6834f1402927 135 //SentralWrite(ALGORITHM_CONTROL,0x02); //update registers with RAW sensor data
awmiller 0:6834f1402927 136 //SentralWrite(ALGORITHM_CONTROL,0x00); //update registers with Scaled sensor data
awmiller 0:6834f1402927 137
awmiller 0:6834f1402927 138 //SentralWrite(HOST_CONTROL_REG,0x01); //Request CPU to run
awmiller 0:6834f1402927 139 cmd[0] = HOST_CONTROL_REG;
awmiller 0:6834f1402927 140 cmd[1]=0x01;
awmiller 0:6834f1402927 141 master.write(SENTRAL_ADDRESS,cmd,2);
awmiller 0:6834f1402927 142 pc.printf("Sentral Startup Success. \r\n");
awmiller 0:6834f1402927 143
awmiller 0:6834f1402927 144 return 1;
awmiller 0:6834f1402927 145 }