Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The code below is for the Reciever NUCLEO
- Written by Riccardo Geraci
- University of Wolverhampton
- Embedded System Design: Developing a CAN BUS diagnostics module for a car
- Oct 2018 - April2019
- Research Srcs: https://os.mbed.com/users/WiredHome/notebook/can---getting-started/
- */
- #include "mbed.h" //Standard includes
- #include "TextLCD.h" //LCD library
- Serial pc(USBTX, USBRX); // tx, rx, needed for console printing, not always needed
- // I2C Communication
- I2C i2c_lcd(D4,D5); // SDA, SCL (These pins are the correct pins for the Nucleo32303K8)
- //i2c old address, the address 0x4F was found by scanning using (lcd.getAddress).
- TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::HD44780); // I2C bus, PCF8574 addr, LCD Type, Ctrl Type
- CAN can(PA_11, PA_12); //rx, tx, CAN object
- DigitalOut rx_can_stat_led(PA_10); //DigitalOut objects for the onboard lcd for showing CAN activity
- DigitalOut rx_power_stat_led(PA_9); //DigitalOut objects for the onboard lcd for showing power status
- int main() //Entry point function
- {
- lcd.setBacklight(TextLCD::LightOn); //Turn on the LCD backlight
- rx_power_stat_led = 1; //Light the led to show the pcb has power
- CANMessage msg; //Define CANMessage object
- while(1) { //infinite loop for continous running
- if (can.read(msg)) { //Returns true if msg is present on the bus
- pc.printf("Message received: %d\r\n", msg.data[0]); //Debugging code
- rx_can_stat_led = !rx_can_stat_led; // Blink the CAN_LED to show activity
- //lcd.cls(); //clear the lcd each time, since the last text doesn't get overwritten by the new
- // pc.printf("volts=%f\ttemperature = %.0f^C\taverage= %.0f^C\r\n", meas, temp, averageTemp);
- //lcd.printf("LM35: %.0f^C", getLM35Temperature());
- // lcd.printf("Rx Msg:%d\r\n", msg.data[0]); //Write the msg data to the LCD
- //lcd.locate(1,0);
- lcd.locate(3,0);
- lcd.printf("Room Temp"); //Code from after seye photos
- lcd.locate(6,1);
- lcd.printf("%dC", msg.data[0]);
- } else {
- // pc.printf("[NO] Message Recieved\r\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement