Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #include <stddef.h>
- #include <stdbool.h>
- #include <math.h>
- /* Driver Header files */
- #include <ti/drivers/GPIO.h>
- /* Example/Board Header files */
- #include "Board.h"
- #include <ti/drivers/UART.h>
- #include <ti/drivers/I2C.h>
- long double BerekenTemp(long double Tdie,long double Vobj)
- {
- long double Tref = 298.15;
- long double a1 = 0.00175;
- long double a2 = -0.00001678;
- long double b0 = -0.0000294;
- long double b1 = -0.00000057;
- long double b2 = 0.00000000463;
- long double c2 = 13.4;
- long double s0 = 5*pow(10,-14); //calibratiefactor
- long double Vobj2 = (double)Vobj*.00000015625;
- long double Tdie2 = (double)Tdie*.03125 + 273.15;
- long double S = s0*(1+a1*(Tdie2 - Tref)+a2*pow((Tdie2 - Tref),2));
- long double Vos = b0 + b1*(Tdie2 - Tref) + b2*pow((Tdie2 - Tref),2);
- long double fObj = (Vobj2 - Vos) + c2*pow((Vobj2 - Vos),2);
- long double Tobj = pow(pow(Tdie2,4) + (fObj/S),.25);
- return Tobj - 273;
- }
- //// Calulate temperature from the TMP006 datasheet
- // long double calculateTemp(int Tdie, int Vobj)
- //{
- // long double Vobj2 = (double)Vobj*.00000015625;
- // long double Tdie2 = (double)Tdie*.03125 + 273.15;
- // long double S0 = 2.867*pow(10,-14); // Tommy's S0
- // //long double S0 = 6.033*pow(10,-14);
- // long double a1 = 1.70*pow(10,-3);
- // long double a2 = -2.0*pow(10,-5);
- // long double b0 = -2.57*pow(10,-5);
- // long double b1 = -9.48*pow(10,-8);
- // long double b2 = 2.26*pow(10,-10);
- // long double c2 = 0;
- // long double Tref = 298.15;
- // long double S = S0*(1+a1*(Tdie2 - Tref)+a2*pow((Tdie2 - Tref),2));
- // long double Vos = b0 + b1*(Tdie2 - Tref) + b2*pow((Tdie2 - Tref),2);
- // long double fObj = (Vobj2 - Vos) + c2*pow((Vobj2 - Vos),2);
- // long double Tobj = pow(pow(Tdie2,4) + (fObj/S),.25);
- // return (Tobj - 273.15);
- //}
- /*
- * ============= mainThread ===============
- *
- * Dit is de 'main' functie van het project
- * Debugger is ingesteld om hier te te pauzeren
- * i.p.v. bij de originele main-functie
- *
- * Tips:
- * 1. Controleer de 'Linked Resources'
- * onder 'project properties' om
- * compilerproblemen te voorkomen
- *
- * 2. Gebruik 'Board.html' uit het project om
- * de pinnamen te zien van de driver
- *
- */
- void *mainThread(void *arg0)
- {
- GPIO_init();
- I2C_init();
- //opens i2c instance
- I2C_Handle i2cHandle;
- I2C_Params i2cParams;
- i2cHandle = I2C_open(Board_I2C0, NULL);
- if (i2cHandle == NULL) {
- // Error opening I2C
- while (1);
- }
- //
- // //i2c transactie, reading from peripheral adress 0x41 (tempsensor), adress 0xFE ( manufacters id)
- // uint8_t readBuffer[2];
- // uint8_t writeBuffer[1] = 0xFE;
- // I2C_Transaction i2cTransaction;
- // i2cTransaction.slaveAddress = 0x41;//adres van de peripheral
- // i2cTransaction.writeBuf = writeBuffer; // adres van het register IN de peripheral dat uitgelezen moet worden
- // i2cTransaction.writeCount = 1; //het adres van het register IN de peripheral dat uitgelezen moet worden moet eerst naar de peripheral geschreven worden
- // i2cTransaction.readBuf = readBuffer;
- // i2cTransaction.readCount = 2;
- // bool status = I2C_transfer(i2cHandle, &i2cTransaction);
- // if (status == false) {
- // // Unsuccessful I2C transfer
- // }
- //i2c transactie, reading from peripheral adress 0x41 (tempsensor)
- uint8_t readBufferTemp[2];
- uint8_t writeBufferTemp[1] = 0x01;
- I2C_Transaction i2cTransactionTemp;
- i2cTransactionTemp.slaveAddress = 0x41;//adres van de peripheral
- i2cTransactionTemp.writeBuf = writeBufferTemp; // adres van het register IN de peripheral dat uitgelezen moet worden
- i2cTransactionTemp.writeCount = 1; //het adres van het register IN de peripheral dat uitgelezen moet worden moet eerst naar de peripheral geschreven worden
- i2cTransactionTemp.readBuf = readBufferTemp;
- i2cTransactionTemp.readCount = 2;
- bool statusTemp = I2C_transfer(i2cHandle, &i2cTransactionTemp);
- if (statusTemp == false) {
- // Unsuccessful I2C transfer
- }
- //i2c transactie, reading from peripheral adress 0x41 (tempsensor)
- uint8_t readBufferSpanning[2];
- uint8_t writeBufferSpanning[1] = 0x00;
- I2C_Transaction i2cTransactionSpanning;
- i2cTransactionSpanning.slaveAddress = 0x41;//adres van de peripheral
- i2cTransactionSpanning.writeBuf = writeBufferSpanning; // adres van het register IN de peripheral dat uitgelezen moet worden
- i2cTransactionSpanning.writeCount = 1; //het adres van het register IN de peripheral dat uitgelezen moet worden moet eerst naar de peripheral geschreven worden
- i2cTransactionSpanning.readBuf = readBufferSpanning;
- i2cTransactionSpanning.readCount = 2;
- bool statusSpanning = I2C_transfer(i2cHandle, &i2cTransactionSpanning);
- if (statusSpanning == false) {
- // Unsuccessful I2C transfer
- }
- int16_t SpanningWaarde = readBufferSpanning[1] | readBufferSpanning[0]<<8;
- int16_t TempWaarde = readBufferTemp[1] | readBufferTemp[0]<<8;
- float SpanningVolt = SpanningWaarde*156.25*pow(10,-9);
- float TempCelsius = TempWaarde<<2;
- TempCelsius = TempCelsius/32;
- float RealTempCelsius = BerekenTemp(SpanningVolt, TempCelsius);
- while(1);
- //opens uart instance, reads byte and writes byte back in terminal
- char input;
- UART_Handle uart;
- UART_Params uartParams;
- // Initialize the UART driver.
- UART_init();
- // Create a UART with data processing off.
- UART_Params_init(&uartParams);
- uartParams.writeDataMode = UART_DATA_BINARY;
- uartParams.readDataMode = UART_DATA_BINARY;
- uartParams.readReturnMode = UART_RETURN_FULL;
- uartParams.readEcho = UART_ECHO_OFF;
- uartParams.baudRate = 115200;
- // Open an instance of the UART drivers
- uart = UART_open(Board_UART0, &uartParams);
- UART_write(uart, "hallo ik ben juul",17 );
- if (uart == NULL) {
- // UART_open() failed
- while (1);
- }
- // Loop forever echoing
- while (1) {
- int vlag = UART_read(uart, &input, 1);
- if(vlag != 0)
- {
- GPIO_toggle(Board_GPIO_LED0);
- }
- UART_write(uart, &input, 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement