Advertisement
TheVideoVolcano

Rx (Oil Temp) - STM32 NUCLEO32-303K8

Jul 15th, 2019
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. /*
  2. The code below is for the Reciever NUCLEO
  3. Written by Riccardo Geraci
  4. University of Wolverhampton
  5. Embedded System Design: Developing a CAN BUS diagnostics module for a car
  6. Oct 2018 - April2019
  7. Research Srcs: https://os.mbed.com/users/WiredHome/notebook/can---getting-started/
  8. */
  9. #include "mbed.h" //Standard includes
  10. #include "TextLCD.h" //LCD library
  11.  
  12. Serial pc(USBTX, USBRX); // tx, rx, needed for console printing, not always needed
  13. // I2C Communication
  14. I2C i2c_lcd(D4,D5); // SDA, SCL (These pins are the correct pins for the Nucleo32303K8)
  15. //i2c old address, the address 0x4F was found by scanning using (lcd.getAddress).
  16. TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::HD44780); // I2C bus, PCF8574 addr, LCD Type, Ctrl Type
  17.  
  18. CAN can(PA_11, PA_12); //rx, tx, CAN object
  19.  
  20. DigitalOut rx_can_stat_led(PA_10); //DigitalOut objects for the onboard lcd for showing CAN activity
  21. DigitalOut rx_power_stat_led(PA_9); //DigitalOut objects for the onboard lcd for showing power status
  22.  
  23. int main()   //Entry point function
  24. {
  25.  
  26.     lcd.setBacklight(TextLCD::LightOn); //Turn on the LCD backlight
  27.     rx_power_stat_led = 1; //Light the led to show the pcb has power
  28.  
  29.     CANMessage msg; //Define CANMessage object
  30.          
  31.     while(1) { //infinite loop for continous running
  32.  
  33.         if (can.read(msg)) { //Returns true if msg is present on the bus
  34.             pc.printf("Message received: %d\r\n", msg.data[0]); //Debugging code
  35.             rx_can_stat_led = !rx_can_stat_led; // Blink the CAN_LED to show activity
  36.  
  37.             //lcd.cls(); //clear the lcd each time, since the last text doesn't get overwritten by the new
  38.             // pc.printf("volts=%f\ttemperature = %.0f^C\taverage= %.0f^C\r\n", meas, temp, averageTemp);
  39.             //lcd.printf("LM35: %.0f^C", getLM35Temperature());
  40.           //  lcd.printf("Rx Msg:%d\r\n", msg.data[0]); //Write the msg data to the LCD
  41.           //lcd.locate(1,0);
  42.          
  43.           lcd.locate(3,0);
  44.           lcd.printf("Room Temp"); //Code from after seye photos
  45.           lcd.locate(6,1);
  46.           lcd.printf("%dC", msg.data[0]);
  47.          
  48.  
  49.         } else {
  50.             // pc.printf("[NO] Message Recieved\r\n");
  51.         }
  52.  
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement