Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio_serial.h"
- #define PORTA_PIO_PDR *(volatile int *) 0x400E0E04
- #define PORTA_PIO_ABCDSR1 *(volatile int *) 0x400E0E70
- #define PORTA_PIO_ABCDSR2 *(volatile int *) 0x400E0E74
- #define PORTB_PIO_PER *(volatile int *) 0x400E1000
- #define PORTB_PIO_PDR *(volatile int *) 0x400E1004
- #define PORTB_PIO_OER *(volatile int *) 0x400E1010
- #define PORTB_PIO_ODR *(volatile int *) 0x400E1014
- #define PORTB_PIO_SODR *(volatile int *) 0x400E1030
- #define PORTB_PIO_CODR *(volatile int *) 0x400E1034
- #define PORTB_PIO_ODSR *(volatile int *) 0x400E1038
- #define PORTB_PIO_PDSR *(volatile int *) 0x400E103C
- #define PORTB_PIO_ABCDSR1 *(volatile int *) 0x400E1070
- #define PORTB_PIO_ABCDSR2 *(volatile int *) 0x400E1074
- #define PORTC_PIO_PER *(volatile int *) 0x400E1200
- #define PORTC_PIO_PDR *(volatile int *) 0x400E1204
- #define PORTC_PIO_OER *(volatile int *) 0x400E1210
- #define PORTC_PIO_ODR *(volatile int *) 0x400E1214
- #define PORTC_PIO_SODR *(volatile int *) 0x400E1230
- #define PORTC_PIO_CODR *(volatile int *) 0x400E1234
- #define PORTC_PIO_ODSR *(volatile int *) 0x400E1238
- #define PORTC_PIO_PDSR *(volatile int *) 0x400E123C
- #define PORTC_PIO_IER *(volatile int *) 0x400E1240
- #define PORTC_PIO_ISR *(volatile int *) 0x400E124C
- #define PORTC_PIO_AIMER *(volatile int *) 0x400E12B0
- #define PORTC_PIO_REHLSR *(volatile int *) 0x400E12D4
- #define UART0_CR *(volatile int *) 0x400E0600
- #define UART0_MR *(volatile int *) 0x400E0604
- #define UART0_IMR *(volatile int *) 0x400E0610
- #define UART0_IER *(volatile int *) 0x400E0608
- #define UART0_IDR *(volatile int *) 0x400E060C
- #define UART0_SR *(volatile int *) 0x400E0614
- #define UART0_RHR *(volatile int *) 0x400E0618
- #define UART0_THR *(volatile int *) 0x400E061C
- #define UART0_BRGR *(volatile int *) 0x400E0620
- #define UART3_CR *(volatile int *) 0x40048000
- #define UART3_MR *(volatile int *) 0x40048004
- #define UART3_SR *(volatile int *) 0x40048014
- #define UART3_RHR *(volatile int *) 0x40048018
- #define UART3_THR *(volatile int *) 0x4004801C
- #define UART3_BRGR *(volatile int *) 0x40048020
- // UART Control Register bits
- #define UART_CR_TXDIS 0x80
- #define UART_CR_TXEN 0x40
- #define UART_CR_RXDIS 0x20
- #define UART_CR_RXEN 0x10
- #define UART_CR_RSTTX 0x08
- #define UART_CR_RSTRX 0x04
- // UART Mode Register bits
- #define UART_MR_NOPARITY 0x800
- // UART Status Register bits
- #define UART_SR_TXRDY 0x02
- #define UART_SR_RXRDY 0x01
- #define SPI_CR *(volatile int *) 0x40008000
- #define SPI_MR *(volatile int *) 0x40008004
- #define SPI_RDR *(volatile int *) 0x40008008
- #define SPI_TDR *(volatile int *) 0x4000800C
- #define SPI_SR *(volatile int *) 0x40008010
- #define SPI_CSR0 *(volatile int *) 0x40008030
- // SPI Control Register bits
- #define SPI_CR_SPIEN 0x01
- // SPI Mode Register bits
- #define SPI_MR_MSTR 0x01
- // SPI Status Register bits
- #define SPI_SR_TDRE 0x02
- #define SPI_SR_RDRF 0x01
- // ADC Registers
- #define ADC_CR *(volatile int *) 0x40038000
- #define ADC_MR *(volatile int *) 0x40038004
- #define ADC_CHER *(volatile int *) 0x40038010
- #define ADC_CHDR *(volatile int *) 0x40038014
- #define ADC_CHSR *(volatile int *) 0x40038018
- #define ADC_IER *(volatile int *) 0x40038024
- #define ADC_ISR *(volatile int *) 0x40038030
- #define ADC_CDR0 *(volatile int *) 0x40038050
- #define ADC_ACR *(volatile int *) 0x40038094
- #define ADC_DMA_BASE 0x40038100 // DMA addresses start at PERIPHERAL_BASE_ADDRESS + 0x100
- #define ADC_DMA_RPR *(volatile int *) (ADC_DMA_BASE + 0x00)
- #define ADC_DMA_RCR *(volatile int *) (ADC_DMA_BASE + 0x04)
- #define ADC_DMA_TCR *(volatile int *) (ADC_DMA_BASE + 0x20)
- #define ADC_DMA_TSR *(volatile int *) (ADC_DMA_BASE + 0x24)
- // ADC Control Register Bits
- #define ADC_START 0x02
- #define ADC_SWRST 0x01
- // ADC Mode Register Bits
- #define ADC_TRANSFER 0x30000000
- #define ADC_PRESCAL PRESCAL_VALUE * 0x100
- #define PRESCAL_VALUE 0x00 // <---- Change this value to change prescaler
- #define ADC_LOWRES 0x10
- #define ADC_TRIG_TC0 0x02
- #define ADC_TRGEN 0x01
- // ADC Channel Enable Register Bits
- #define ADC_EN_CH0 0x01
- // ADC Channel Disable Register Bits
- #define ADC_DIS_CH0 0x01
- // ADC Channel Status Register Bits
- #define ADC_STAT_CH0 0x01
- // ADC Analog Control Register Bits
- #define ADC_IRCE 0x04
- #define ADC_FORCEREF 0x80000
- // ADC Interrupt Register Bits
- #define ADC_RXBUFF_INT 0x10000000
- // DMA Controller Transfer Control Register Bits
- #define DMA_RC_EN (1 << 0)
- // timer0 channel 0 registers
- #define TC_CCR0_CH0 *(volatile int *) 0x40010000
- #define TC_CMR0_CH0 *(volatile int *) 0x40010004
- #define TC_CVR0_CH0 *(volatile int *) 0x40010010
- #define TC_RA0_CH0 *(volatile int *) 0x40010014
- #define TC_RB0_CH0 *(volatile int *) 0x40010018
- #define TC_RC0_CH0 *(volatile int *) 0x4001001C
- #define TC_SR0_CH0 *(volatile int *) 0x40010020
- #define TC_IER0_CH0 *(volatile int *) 0x40010024
- #define TC_IDR0_CH0 *(volatile int *) 0x40010028
- #define TC_IMR0_CH0 *(volatile int *) 0x4001002C
- // Timer0 Channel 0 Channel Control Register Bits
- #define CCR_SWTRG 0x04
- #define CCR_CLKDIS 0x02
- #define CCR_CLKEN 0x01
- // Timer0 Channel 0 Channel Mode Register Bits
- #define CMR_WAVE_EN 0x8000
- #define CMR_WAVE_SEL 0x4000
- #define CMR_DIV_128 0x03
- #define CMR_DIV_32 0x02
- #define CMR_DIV_2 0x00
- // Timer0 Channel 0 Status Register Bits
- #define SR_CPCS 0x10
- // Timer0 Channel 0 Interrupt Enable/Disable/Mask Register Bits
- #define INT_CPCS 0x10
- #define INT_CPAS 0x04
- // PWM Module 0
- #define PWM_MR *(volatile int *) 0x40020000
- #define PWM_ENA *(volatile int *) 0x40020004
- #define PWM_DIS *(volatile int *) 0x40020008
- #define PWM_SR *(volatile int *) 0x4002000C
- #define PWM_CMR0 *(volatile int *) 0x40020200
- #define PWM_CDTY0 *(volatile int *) 0x40020204
- #define PWM_CPRD0 *(volatile int *) 0x40020208
- #define PWM_CCNT0 *(volatile int *) 0x4002020C
- #define PWM_CUPD0 *(volatile int *) 0x40020210
- #define CHID0 0x01
- // Declare any global variables here
- unsigned short x_position, y_position;
- unsigned char buttons;
- /*** ADC DMA Buffer ***/
- #define DATA_SIZE 1024
- #define DATA_SIZE_SMALL 32
- unsigned short adc_array[DATA_SIZE] = {0};
- unsigned char xmt_buffer[DATA_SIZE] = {0};
- unsigned char rcv_buffer[DATA_SIZE_SMALL] = {0};
- unsigned char rcv_buf_cnt = 0;
- unsigned short xmt_buf_cnt = 0;
- unsigned char * xmt_buf_in = 0;
- unsigned char * xmt_buf_out = 0;
- unsigned char * rcv_buf_in = 0;
- unsigned char * rcv_buf_out = 0;
- unsigned char * end_of_xmt_buffer = 0;
- unsigned char * end_of_rcv_buffer = 0;
- unsigned char * beginning_of_rcv_buffer = 0;
- // Interrupt Service Routines go here
- /* Timer0 ISR */
- void TC0_Handler() {
- // Declare variables
- unsigned short timer0_status;
- // Read the Status Register (this also clears the interrupt)
- timer0_status = TC_SR0_CH0;
- }
- void ADC_Handler() {
- // Declare variables
- unsigned int adc_status;
- // Read the Status Register (this also clears the interrupt)
- adc_status = ADC_ISR;
- // Set the Receive Pointer Register in the ADC DMA controller
- ADC_DMA_RPR = (int) adc_array; // type cast to suppress warnings
- // Set the Receive Counter in the ADC DMA controller
- ADC_DMA_RCR = DATA_SIZE;
- }
- void UART0_Handler()
- {
- unsigned char ch, ch2;
- //unsigned int status_reg;
- //status_reg = UART0_SR;
- if (UART0_SR & UART_SR_RXRDY)
- {
- // grab character from RHR
- ch = UART0_RHR;
- // set data in address of rcv_buf_in to ch
- *rcv_buf_in = ch;
- // increment buf counter
- rcv_buf_cnt++;
- // increment rcv_buf_in pointer
- rcv_buf_in++;
- // check if @ end of buffer
- if (rcv_buf_in == end_of_rcv_buffer)
- {
- rcv_buf_in = &rcv_buffer;
- }
- }
- if (UART0_SR & UART_SR_TXRDY)
- {
- // grab character at xmit_buf_out
- ch2 = *xmt_buf_out;
- // send the character via THR
- UART0_THR = ch2;
- // increment pointer
- xmt_buf_out++;
- // if at end, set back to beginning
- if (xmt_buf_out == end_of_xmt_buffer)
- {
- xmt_buf_out = &xmt_buffer;
- }
- // decrement buf_cnt
- xmt_buf_cnt--;
- // if we're out of characters
- if(!xmt_buf_cnt)
- {
- //disable TXRDY interrupt by setting it high on IDR
- UART0_IDR = UART_SR_TXRDY;
- }
- }
- }
- // Function prototypes for user defined subroutines
- void our_ioport_init();
- void stdio_uart_init();
- void uart3_init();
- void spi_init();
- void adc_init();
- void timer_init();
- void pwm_init();
- void PutCharacter(unsigned char ch);
- void PutString(unsigned char string[]);
- void delay_ms(unsigned short delay_time);
- void delay_us(unsigned short delay_time);
- void spi_joystick_exchange(unsigned char leds);
- void my_puts(unsigned char *);
- int main(void)
- {
- // Declare local variables
- unsigned short adc_data=0; // raw A/D value: between 0 and 1023 (0x000 and 0x3FF)
- unsigned int dma_ptr = 0;
- unsigned int dma_ctr = 0;
- unsigned short tmp = 0;
- unsigned short tmp2 = 0;
- unsigned char ch = 0;
- // enable interrupts on uart0
- NVIC_EnableIRQ(UART0_IRQn);
- // Initialize the SAM4 board
- sysclk_init();
- board_init();
- // Initialize the I/O ports
- our_ioport_init();
- // Initialize UART3 to send data to the Serial LCD
- uart3_init();
- stdio_uart_init();
- // Initialize the ADC and start the first conversion
- adc_init();
- // Initialize Timer 0 for interrupts
- timer_init();
- // Clear any previous stuff off of the terminal screen
- puts("\x1b[2J\x1b[H");
- // initialize the xmt and rcv buffer pointers
- xmt_buf_in = &xmt_buffer;
- xmt_buf_out = &xmt_buffer;
- rcv_buf_in = &rcv_buffer;
- rcv_buf_out = &rcv_buffer;
- end_of_xmt_buffer = &xmt_buffer;
- end_of_xmt_buffer = end_of_xmt_buffer + 1024;
- end_of_rcv_buffer = &rcv_buffer;
- end_of_rcv_buffer = end_of_rcv_buffer + 32;
- beginning_of_rcv_buffer = &rcv_buffer;
- xmt_buf_cnt = 0;
- rcv_buf_cnt = 0;
- // enable RXRDY interrupt via uart IER
- UART0_IER = UART_SR_RXRDY;
- printf("Testing input, first.\r\n");
- for (tmp = 0; tmp < 100; tmp++)
- {
- for (tmp2 = 0; tmp2 < 2; tmp2++)
- {
- my_puts("\r\nTesting input again.");
- }
- }
- printf("Data is : \r\n");
- while (rcv_buf_cnt)
- {
- // get new char from rcv_buf
- ch = *rcv_buf_out;
- // display it
- putchar(ch);
- rcv_buf_cnt--;
- rcv_buf_out++;
- if (rcv_buf_out == end_of_rcv_buffer)
- {
- rcv_buf_out = &rcv_buffer;
- }
- }
- //printf("Data is : \r\n");
- //printf(beginning_of_rcv_buffer);
- while (1)
- {
- /*my_puts("Testing input again.\r\n");
- if (rcv_buf_cnt)
- {
- // get new char from rcv_buf
- ch = *rcv_buf_out;
- // display it
- putchar(ch);
- rcv_buf_cnt--;
- rcv_buf_out++;
- if (rcv_buf_out == end_of_rcv_buffer)
- {
- rcv_buf_out = &rcv_buffer;
- }
- }
- */
- }
- /* Infinite loop
- while (true)
- {
- Make a copy of where the DMA is currently operating
- /* previous lab
- dma_ptr = ADC_DMA_RPR;
- dma_ctr = ADC_DMA_RCR;
- printf("dma_ptr=0x%x dma_ctr=0x%3x \r", dma_ptr, dma_ctr);
- } // end of infinite while loop
- */
- } // end of main
- // User defined subroutines
- void our_ioport_init() {
- // Configure Port A for Peripheral A functionality on bits 0-31
- PORTA_PIO_PDR = 0xFFFFFFFF; // Disable all bits
- PORTA_PIO_ABCDSR1 = 0x01; // Assign all bits for Peripheral A functions
- PORTA_PIO_ABCDSR2 = 0x00;
- // Configure Port B for General Purpose Input/Output (GPIO) functionality on bits 0-3 and 14,
- PORTB_PIO_PER = 0x0000400F; // Enable bits 0-3 and 14
- PORTB_PIO_OER = 0x0000400F; // Make bits 0-3 and 14 as outputs
- // assign bits 10 and 11 for Peripheral B functionality
- PORTB_PIO_PDR = 0x00000C00; // Disable bits 10 and 11
- PORTB_PIO_ABCDSR1 = 0xC00; // Assign bits 10 and 11 for Peripheral B functions
- PORTB_PIO_ABCDSR2 = 0x000; // (RX and TX for UART3)
- // Configure Port C for General Purpose Input/Output (GPIO) functionality on bits 0-3
- PORTC_PIO_PER = 0x0000000F; // Enable bits 0-3
- PORTC_PIO_ODR = 0x0000000F; // Make bits 0-3 as inputs
- // Configure Port C, bit 0 to generate an interrupt on a rising edge
- //PORTC_PIO_IER = 0x01; // Enable bit 0 for interrupts
- //PORTC_PIO_AIMER = 0x01; // Set bit 0 for additional information
- //PORTC_PIO_REHLSR = 0x01; // Set bit 0 for rising edge
- // Enable Port C interrupts
- //NVIC_EnableIRQ(PIOC_IRQn);
- }
- void stdio_uart_init() {
- // Required data for UART0
- const usart_serial_options_t uart_serial_options = {
- .baudrate = CONF_UART_BAUDRATE,
- .paritytype = CONF_UART_PARITY,
- };
- // Initialize the Standard I/O UART to UART0
- pmc_enable_periph_clk(CONSOLE_UART_ID);
- stdio_serial_init(CONF_UART, &uart_serial_options);
- }
- void uart3_init() {
- // Assign a clock signal to this peripheral.
- pmc_enable_periph_clk(ID_UART3);
- // Configure UART3 for 9600 baud and no parity. Data length of 8 bits and 1 stop bit are default values.
- // Set the baud rate to 9600 as per the formula provided.
- UART3_BRGR = ((100000000/9600)/16);
- // Set the mode to no parity.
- UART3_MR = UART_MR_NOPARITY;
- // Lastly enable the UART3 receiver and transmitter.
- UART3_CR = UART_CR_RXEN | UART_CR_TXEN;
- }
- void spi_init() {
- // Assign a clock signal to this peripheral
- pmc_enable_periph_clk(ID_SPI);
- // First disable the SPI module through the Control Register
- SPI_CR = SPI_CR_SPIDIS;
- // Next reset the SPI module
- SPI_CR = SPI_CR_SWRST;
- // Next configure for Master mode through the Mode Register
- SPI_MR = SPI_MR_MSTR;
- // Next configure the SPI serial clock baud rate (SCBR) for 1 MHz (100 MHz / 100)
- SPI_CSR0 = SPI_CSR_NCPHA + 0x6400;
- // Last enable the SPI module through the Control Register
- SPI_CR = SPI_CR_SPIEN;
- // Set the Slave Select line high on Port B, bit 0
- PORTB_PIO_SODR = 0x01;
- }
- void adc_init() {
- // Assign a clock signal to this peripheral
- pmc_enable_periph_clk(ID_ADC);
- // Set the transfer bits to 2 in the Mode Register <MUST ALWAYS BE DONE>
- // and set the A/D to trigger on the TIOA output signal from Timer Counter 0
- ADC_MR = ADC_TRANSFER + ADC_PRESCAL + ADC_TRIG_TC0 + ADC_TRGEN;
- // Enable channel 0 of the ADC in the Channel Enable Register
- ADC_CHER = ADC_EN_CH0;
- // Enable internal reference voltage and force internal reference voltage VDDIN
- // in the Analog Control Register
- ADC_ACR = ADC_IRCE + ADC_FORCEREF;
- // Set the Receive Pointer Register in the ADC DMA controller
- ADC_DMA_RPR = (int) adc_array; // type cast to suppress warnings
- // Set the Receive Counter in the ADC DMA controller
- ADC_DMA_RCR = DATA_SIZE;
- // Enable the DMA receiver
- ADC_DMA_TCR = DMA_RC_EN;
- // Configure for ADC RXBUFF interrupt when the DMA counter reaches 0
- ADC_IER = ADC_RXBUFF_INT;
- // Enable interrupts for the ADC
- NVIC_EnableIRQ(ADC_IRQn);
- // Start the first conversion of the ADC in the Control Register
- // ADC_CR = ADC_START;
- }
- void timer_init() {
- // Assign a clock signal to this peripheral.
- pmc_enable_periph_clk(ID_TC0);
- // Divide the peripheral clock by 128 (100 MHz / 128 = 781.25 kHz)
- // Enable waveform mode
- TC_CMR0_CH0 = 0xC0000 + CMR_DIV_128 + CMR_WAVE_EN + CMR_WAVE_SEL;
- // Load the RC register with a value to interrupt every 20 ms (50 interrupts per second)
- TC_RC0_CH0 = 0x4000;
- // Enable the RA compare interrupt
- //TC_IER0_CH0 = INT_CPCS;
- // Enable interrupts for timer0
- //NVIC_EnableIRQ(TC0_IRQn);
- // Enable the timer
- TC_CCR0_CH0 = CCR_CLKEN + CCR_SWTRG;
- }
- void pwm_init() {
- // Assign a clock signal to this peripheral.
- pmc_enable_periph_clk(ID_PWM);
- // Set up for CLKA to be MCLK / 32 / 3 = 1.041667 MHz
- PWM_MR = 0x05 * 0x100 + 3;
- // Set up the PWM to use CLKA and set the polarity to 1
- PWM_CMR0 = 0x2 * 0x100 + 0x0B;
- // Set up the period to be around 0.5 msec (2 kHz) by setting CPRD = 511
- // CLKA / CPRD = 1.041667 MHz / 511 = 2038.48 Hz
- PWM_CPRD0 = 511;
- // Set up for a 0% duty cycle to start
- PWM_CDTY0 = 0;
- // Enable the PWM Module
- PWM_ENA = CHID0;
- }
- void PutCharacter(unsigned char ch) {
- // Declare variables
- unsigned char status;
- // Read the UART3 Status register
- status = UART3_SR;
- // Mask out the Transmit Ready bit
- status = status & UART_SR_TXRDY;
- // Is the TXRDY bit set? If not, then re-read and re-mask
- while (status == 0x00) {
- // Re-read the UART3 Status Register
- status = UART3_SR;
- // Re-mask out the TXRDY bit
- status = status & UART_SR_TXRDY;
- }
- // The TXRDY bit is set, so send the character on the Transmit line
- // by writing it into the Transmit Holding Register (THR)
- UART3_THR = ch;
- }
- // Added before 10/26 lab
- void my_puts(unsigned char * tmp)
- {
- // get the first character from the string and increment pointer
- unsigned char ch;
- ch = *tmp;
- tmp++;
- while (ch)
- {
- // increment xmt_buffer counter
- xmt_buf_cnt++;
- // store this character in the xmt_buffer using xmt_buf_in pointer
- * xmt_buf_in = ch;
- // increment ^ pointer
- xmt_buf_in++;
- // at the end of buffer?
- if (xmt_buf_in == end_of_xmt_buffer)
- {
- // set pointer to the beginning of the buffer
- xmt_buf_in = &xmt_buffer;
- }
- // get next character from string and increment the string pointer
- ch = *tmp;
- tmp++;
- }
- // if we get here, ch == 0
- // read UART IMT and mask out TXRDY
- // enable txrdy interrupt via uart IER if status = 0)
- if (!(UART0_IMR & UART_SR_TXRDY))
- UART0_IER = UART_SR_TXRDY;
- return;
- }
- void PutString(unsigned char string[]) {
- // Declare variables
- unsigned char i, ch;
- // Initialize index counter
- i = 0;
- // Send characters using PutCharacter until the null character is found
- while ((ch = string[i]) != 0x00) {
- PutCharacter(ch);
- // increment the index counter
- i++;
- }
- }
- void delay_ms(unsigned short delay_time) {
- // Declare variables
- unsigned short i;
- // outer loop
- while (1) {
- // inner for loop
- // Wait 1 millisecond
- for (i=0; i<7600; i++) {
- // do nothing
- }
- // decrement delay_time
- delay_time--;
- // see if it is time to leave
- if (delay_time == 0) {
- // break out of this infinite loop
- break;
- }
- }
- }
- void delay_us(unsigned short delay_time) {
- // Declare variables
- unsigned char i;
- // outer loop
- while (1) {
- // inner for loop
- // Wait 1 millisecond
- for (i=0; i<8; i++) {
- // do nothing
- }
- // decrement delay_time
- delay_time--;
- // see if it is time to leave
- if (delay_time == 0) {
- // break out of this infinite loop
- break;
- }
- }
- }
- void spi_joystick_exchange(unsigned char leds) {
- // Declare variables
- unsigned char x_low, x_high, y_low, y_high;
- // Set SS low on Port B, bit 3
- PORTB_PIO_CODR = 0x08;
- delay_us(3);
- SPI_TDR = 0x80 + leds;
- while ((SPI_SR & SPI_SR_RDRF) == 0x00) {
- // wait until RDRF is set
- }
- x_low = SPI_RDR;
- delay_us(8);
- SPI_TDR = 0x11;
- while ((SPI_SR & SPI_SR_RDRF) == 0x00) {
- // wait until RDRF is set
- }
- x_high = SPI_RDR;
- delay_us(8);
- SPI_TDR = 0x22;
- while ((SPI_SR & SPI_SR_RDRF) == 0x00) {
- // wait until RDRF is set
- }
- y_low = SPI_RDR;
- delay_us(8);
- SPI_TDR = 0x44;
- while ((SPI_SR & SPI_SR_RDRF) == 0x00) {
- // wait until RDRF is set
- }
- y_high = SPI_RDR;
- delay_us(8);
- SPI_TDR = 0x88;
- while ((SPI_SR & SPI_SR_RDRF) == 0x00) {
- // wait until RDRF is set
- }
- buttons = SPI_RDR;
- PORTB_PIO_SODR = 0x08;
- x_position = x_high * 0x100 + x_low;
- y_position = y_high * 0x100 + y_low;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement