Search for question
Question

Name Question 1: Basics 1.1. What is the result of b in binary? 1.2. Is the following statement correct? b = 0x11<<3 int asd=0.5; 1.3. In a C program, what does the following code do? x &= A. Clear a bit B. Set a bit C. Toggle a bit ~ · (1<<k); E. Check a bit A. Clear a bit 1.4. In a C program, what does the following code do? B. Set a bit C. Toggle a bit × |= 1<<k; E. Check a bit 1.5.Please write the results for each: 0x35 & 0x2E = 0x46 ^ 0x78 = 0x130x58 = 1.6. If variables p1 and p2 are declared by: int *p1, p2; please tell their data types. Question 2: GPIOX 2.1 How man pins does GPIOA contain? 2.2 What is GPIOX-> MODER? 2.3 The following is GPIO_MODER, please configure GPIOB pin12 as alternate function. 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 MODE15[1:0] MODE14[1:0] MODE13[1:0] MODE12[1:0] MODE11[1:0] MODE10[1:0] MODE9[1:0] MODE8[1:0] rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 MODE7[1:0] MODE6[1:0] MODE5[1:0] MODE4[1:0] MODE3[1:0] MODE2[1:0] MODE1[1:0] MODE0[1:0] rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw 1 Name Bits 2y+1:2y MODEY [1:0]: Port x configuration bits (y = 0..15) These bits are written by software to configure the I/O mode. 00: Input mode 01: General purpose output mode 10: Alternate function mode 11: Analog mode (reset state) Access ID 2.4 The following is GPIO_BSRR, please reset GPIOC pin 6 and set GPIOD pin 12. 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 160 16 BR15 BR14 BR13 BR12 BR11 BR10 BR9 BR8 BR7 BR6 BR5 BR4 BR3 BR2 BR1 BRO W W W W W W W W W W W W W W W W 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 BS15 BS14 BS13 BS12 BS11 BS10 BS9 BS8 BS7 BS6 BS5 BS4 BS3 BS2 BS1 BSO W W W W W W W W W W W W W W W W Bits 31:16 BR[15:0]: Port x reset I/O pin y (y = 15 to 0) These bits are write-only. A read to these bits returns the value 0x0000. 0: No action on the corresponding ODx bit 1: Resets the corresponding ODx bit Note: If both BSX and BRX are set, BSX has priority. Bits 15:0 BS[15:0]: Port x set I/O pin y (y = 15 to 0) These bits are write-only. A read to these bits returns the value 0x0000. 0: No action on the corresponding ODx bit 1: Sets the corresponding ODx bit Question 3: Timer and Interrupt 3.1 Is timer a counter? 3.2 Use equation: CK_CNT = fCK PSC PSC+1 to find prescaler PSC if system clock is 3 million HZ and Timer clock is 2500HZ. 3.3 The following is TIM_CR1, please write a line of C code to enable timer. 2 Name Reset value: 0x0000 9/8-765 15 14 13 12 11 10 Res. Res. Res Res. UIFRE MAP Res. CKD[1:0] rw ARPE CMS[1:0] Access ID 432 1 0 DIR OPM URS UDIS CEN rw rw rw rw rw rw rw rw rw rw 3.4 If we use PD14 as interrupt input, please configure the following SYSCFG_EXTICR4. 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 Res. Res. Res. Res Res. Res. Res. Res. Res. Res Res. Res. Res. Res. Res Res 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 EXTI14[3:0] EXTI13[3:0] EXTI12[3:0] rw rw rw rw rw rw rw rw rw rw rw rw rw rw EXTI15[3:0] rw rw Question 4: ADC and DAC 4.1 The following is ADC_CR, please write a line of C code to exit deep-power-down status 31 30 29 28 ADCA ADCA DEEP ADVREG L LDIF PWD EN 27 26 25 24 23 22 21 20 19 18 17 16 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res Res Res. rs rw rw rw 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Res Res Res Res. Res. Res. Res. Res. Res. Res. JADST P ADSTP JADST ADSTA ART RT ADDIS ADEN rs rs rs rs rs rs Bit 29 DEEPPWD: Deep-power-down enable This bit is set and cleared by software to put the ADC in Deep-power-down mode. 0: ADC not in Deep-power down 1: ADC in Deep-power-down (default reset state) 4.2 Using the RCC_APB1ENR1 in Question (3), please enable DAC1 clock. 3 Name Question 5: USART 5.1 What is half duplex communication? 5.2 In USART, can we have multiple stop bits in a data frame ? 5.3 If baud rate is 9600bps, how many seconds to transfer 2M bits Access ID 5.4 The following is USART_CR1, please write two lines of C Code to enable Receiver and USART 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 Res. Res. Res. M1 EOBIE RTOIE DEAT[4:0] DEDT[4:0] rw rw rw rw rw rw rw rw rw rw rw rw rw 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 OVER8 CMIE MME MO WAKE PCE PS PEIE TXEIE TCIE RXNEIE IDLEIE TE RE UESM UE rw rw rw rw rw rw M rw rw rw rw rw rw rw rw rw rw Question 6: SPI 6.1 In SPI, please spell out MOSI, MISO, SS, and SCLK 6.2 In SPI, if CPOL=0, what does it mean? and if CPHA=0, what does it mean? 6.3 The following is RCC_APB1ENR1. Write a line of C code to enable SP13 clock 4 Name Access ID 31 30 29 28 27 26 25 24 24 23 22 21 20 20 19 18 17 16 | LPTIM1| OPAMP | DAC1 PWR Res CAN2 CAN1 12C3 12C2 12C1 UART5 CRSEN EN EN EN EN EN EN EN EN EN EN UART4 USART3 USART2 EN EN EN Res. rw rw rw rw rw rw rw rw rw rw rw rw rw rw 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 SP13 SPI2 Res. Res. EN EN WWD GEN PBEN RTCA LCD TIM7 TIM3EN TIM2 Res. Res. Res. TIM6EN TIM5EN TIM4EN EN EN EN rw rw rs rw rw rw rw rw rw rw rw 5