Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ECE6483 – RealTime Embedded Systems

EXAM 2 / Spring 2024

Question 1:

Please evaluate and explain the following statements(2 or 3 sentences each):

a.    An interrupt is typically a high priority, urgent task.

b.    Using interrupts is always faster than polling.

c.    System latency is always larger than interrupt latency

d.    Global variables used within an ISR should always be declared volatile.

e.    The interrupt vector table must be placed in a specific location in memory.

f.    An ISR can return a value and take arguments

g.    It is OK for an ISR to safely access the SPI bus that has multiple slaves.

h.    If you enable an interrupt in your C code, but don’t define the ISR, what code executes when the interrupt is triggered?

i.     According to the datasheet of our ARM CORTEX F4, which pins can fire pin change interrupts?

Question 2:

a.    Draw the timing diagram for SDA and SCK that shows a master writing two bytes of data to slave at address (7 bit address) 0x13.  The first byte is 0x50 and the second byte is 0x33.  The master    should release the bus afterwards.

b.    Show the timing diagram like in a., but for a simple single byte “echo” transaction.  That is, the master sends one byte, “A” for example, and the slave sends back the same “A” to the master.

Please be as precise as you can with the timing diagrams!!!!

Question 3:

Suppose you are required to retrieve the X, Y , and Z acceleration raw data from a standard ADXL345 accelerometer. You may assume that the device is connected properly and configured already and you have access to 5 functions provided by the HAL as described below.

a. int Start_I2C()

i.    Initializes all of the I2C hardware pins etc. Returns 1 if successful, 0 otherwise

b. int I2C_Write_Byte(uint8_t data)

i.   Writes ‘data’ on the I2C Bus. Returns 1 if slave ACK, 0 is slave NAK

c. int I2C_Send_Start_Condition(uint8_t address, int isRead)

i.   Send a start or restart condition, followed by 7-bit address, followed by ‘isRead’ bit, which is 0 if write, 1 if read.

ii.    Returns 1 if successful, 0 otherwise

d. int I2C_Send_Stop_Condition()

i.    returns 1 if successful, 0 otherwise

e. int I2C_Request_Read(uint8_t *buffer, int numBytes)

i.    reads ‘numBytes’ bytes off the bus, each followed by an master ACK except for the last byte, which if followed by a master NAK indicating an end to the read.  Returns 1 if it gets all the bytes, 0 otherwise and buffer holds the bytes.

Find the datasheet for the ADXL345 online and find the relevant details for the I2C bus serial communications and the Register map. Using the datasheet, write a C code function:

uint8_t GetXL(uint16_t *x, uint16_t *y, uint16_t *z)

The function should fetch the raw acceleration data in all three axis.  You can add any additional variables as long as you state what they are for and be sure to state any assumptions made.

Question 4:

2.   The requirement for this question is to use interrupts to measure the time elapsed while a single button (GPIO) is being pressed.  The GPIO pin is pulled to a high state when the button is not depressed.  In this application, the button is mechanical and experiences significant bouncing. The goal is to measure the contiguous time (in ms) between when the button is pressed (and  settled after bouncing) and when the button is initially released, excluding the bouncing.  See  diagram below.  The duration of the pulse is on the order of 1 second.

You have already setup 3 interrupt handlers.  One handler is the ISR that handles Timer0’s overflow.  That timer is set up with a prescaler of 32, a counter TOP value of 250, and is set up to reset to 0 and count up to TOP. The CLK is running at 8MHz.  Here is the handler definition:

Void Timer0_OV_Handler()

The other 2 handlers are for the pin that is connected to the button.  One handles the RISING transition, and the other handles the FALLING transition.  Here are the definitions:

void pinRising_Handler()

void pinFalling_Handler()

Write the required code snipits (in each handler) that assigns the variable timeElapsed to the specified time in the timing diagram.  You may add any additional variables, but be sure to state any assumptions.