/////////////////////////////////////////////////////////////////////// // // alt_core module // // this is the behavioural model of the sports altimeter without pads // /////////////////////////////////////////////////////////////////////// `include "options.sv" module alt_core( output logic RS, output logic RnW, output logic E, input [7:0] DB_In, output logic [7:0] DB_Out, output logic DB_nEnable, input nMode, nTrip, output logic SCL, input SDA_In, output logic SDA_Out, input Clock, nReset ); timeunit 1ns; timeprecision 100ps; const logic [6:0] simple_sensor_i2c_device_address = 7'b0001000; const logic [6:0] bmp390_i2c_device_address = 7'b1110110; const logic i2c_read = '1; const logic i2c_write = '0; const logic i2c_acknowledge = '0; const logic i2c_not_acknowledge = '1; // the following is behavioural (unsynthesizable) code to trigger // regular data reads from the sensor but makes no attempt to // interpret the data returned (it ignores the SDA_In signal) task i2c_start(); SDA_Out = '1; // this will give either a start or repeated start // dependent on whether the bus is idle #1ms SCL = '1; #1ms SDA_Out = '0; #1ms SCL = '0; #1ms SDA_Out = '0; endtask task i2c_stop(); SDA_Out = '0; SCL = '0; #1ms SCL = '1; #1ms SDA_Out = '1; #2ms SDA_Out = '1; endtask task i2c_data1( logic value ); SDA_Out = value; SCL = '0; #1ms SCL = '1; #2ms SCL = '0; #1ms SCL = '0; endtask task i2c_data8( logic [7:0] value ); int i; for ( i = 7; i >= 0; i--) i2c_data1( value[i] ); endtask always begin SCL = '1; SDA_Out = '1; #2s i2c_start(); // first byte includes device address and either a read // or a write request i2c_data8( { simple_sensor_i2c_device_address, i2c_read } ); // receive acknowledge i2c_data1( '1 ); // setting SDA_Out = 1 allows sensor to drive the SDA line // receive first data byte i2c_data8( 8'b11111111 ); // setting SDA_Out = 1 allows sensor to drive the SDA line // send ACK for first data byte i2c_data1( i2c_acknowledge ); // receive second data byte i2c_data8( 8'b11111111 ); // setting SDA_Out = 1 allows sensor to drive the SDA line // send ACK for second data byte i2c_data1( i2c_acknowledge ); // receive third data byte i2c_data8( 8'b11111111 ); // setting SDA_Out = 1 allows sensor to drive the SDA line // send NACK to indicate no further bytes are expected i2c_data1( i2c_not_acknowledge ); i2c_stop(); end // this module makes no attempt to communicate with the LCD assign RS = '0; assign RnW = '1; assign E = '0; assign DB_Out = '0; assign DB_nEnable = '1; endmodule