int cmd_init_slave(int argc, char **argv) { int res; spi_master = -1; if (parse_spi_dev(argc, argv) < 0) { return 1; } spi_acquire(spi_dev); res = spi_init_slave(spi_dev, spi_mode, slave_on_data); spi_release(spi_dev); if (res < 0) { printf("spi_init_slave: error initializing SPI_%i device (code: %i)\n", spi_dev, res); return 1; } res = gpio_init_int(spi_cs, GPIO_IN, GPIO_FALLING, slave_on_cs, 0); if (res < 0){ printf("gpio_init_int: error initializing GPIO_%ld as CS line (code %i)\n", (long)spi_cs, res); return 1; } spi_master = 0; printf("SPI_%i successfully initialized as slave, cs: GPIO_%ld, mode: %i\n", spi_dev, (long)spi_cs, spi_mode); return 0; }
int main() { spi_init_slave(); //Ativa os dois sensores clr_bit(DDRD, SENSOR1); clr_bit(DDRD, SENSOR2); EICRA = (1 << ISC01) |(1 << ISC11); //interrupcoes no INT0 na borda de descida EIMSK = (1 << INT0); //habilita a interrupcao INT0 TIMSK1 |= 1<<OCIE1A; TCCR1B |= (1 << WGM12) | (1 << CS12) | (1 << CS10); /*cada um segundo 7812 * 1000ms 7812 * 1 ms x = 8 */ OCR1A= 8; #if DEBUG uart_init(); uart_sendSTR("Iniciou agente RPM\n"); #endif sei(); while (1); }
void init_IO() { clr_bit(DDRC,PC0); clr_bit(PORTC,PC0); clr_bit(DDRC,PC1); clr_bit(PORTC,PC1); spi_init_slave(); adc_init(); }
/**************************************************************************//** * @brief Refresh the LS013B7DH03 display device. * * @param[in] device Display device pointer. * * @return EMSTATUS code of the operation. *****************************************************************************/ static EMSTATUS DriverRefresh(DISPLAY_Device_t* device) { EMSTATUS status = DISPLAY_EMSTATUS_OK; (void) device; /* Suppress compiler warning: unused parameter. */ /* Reinitialize the timer and SPI configuration. */ PAL_TimerInit(); spi_handle = spi_init(0, PAL_SPI_BAUDRATE, 8, false, 0); // TODO defines from platform lcd_spi_handle = spi_init_slave(spi_handle, A10, false); return status; }
void cmd_init_slave(int argc, char **argv) { int res; spi_master = -1; if (parse_spi_dev(argc, argv) < 0) { return; } res = spi_init_slave(spi_dev, spi_mode, slave_on_data); if (res < 0) { printf("spi_init_slave: error initializing SPI_%i device (code: %i)\n", spi_dev, res); } res = gpio_init_int(spi_cs, GPIO_NOPULL, GPIO_FALLING, slave_on_cs, 0); if (res < 0){ printf("gpio_init_int: error initializing GPIO_%i as CS line (code %i)\n", spi_cs, res); } spi_master = 0; printf("SPI_%i successfully initialized as slave, cs: GPIO_%i, mode: %i\n", spi_dev, spi_cs, spi_mode); return; }
int main(void) { for (int i=0; i<MAX_SENSOR_COUNT; i++) { sensor_data[i] = 0; } spi_init_slave(); //Initialize slave SPI sei(); while(1) { for (int i=0; i<MAX_SENSOR_COUNT; i++) { sensor_data[i] = poll_sensor(i); _delay_ms(40); } /* PORTB ^= (1 << PB0); _delay_ms(500); PORTB ^= (1 << PB0); _delay_ms(500); */ } }
int main(void) { lcd_init(LCD_DISP_ON_CURSOR_BLINK); //Initialize LCD spi_init_slave(); //Initialize slave SPI unsigned char data, buffer[10]; DDRA = 0x00; //Initialize PORTA as INPUT PORTA = 0xFF; //Enable Pull-Up Resistors while(1) { lcd_clrscr(); //LCD Clear screen lcd_home(); //LCD move cursor to home lcd_puts("Testing"); lcd_gotoxy(0,1); data = spi_tranceiver(ACK); //Receive data, send ACK itoa(data, buffer, 10); //Convert integer into string lcd_puts(buffer); //Display received data _delay_ms(20); //Wait } }
/**************************************************************************//** * @brief Initialize the LS013B7DH03 display driver * * @return EMSTATUS code of the operation. *****************************************************************************/ EMSTATUS DISPLAY_Ls013b7dh03Init(void) { DISPLAY_Device_t display; EMSTATUS status; /* Initialize the Platform Abstraction Layer (PAL) interface. */ PAL_TimerInit(); // TODO spi_handle = spi_init(0, PAL_SPI_BAUDRATE, 8, false, 0); // TODO defines from platform lcd_spi_handle = spi_init_slave(spi_handle, A10, false); #if defined( LCD_PORT_DISP_PWR ) PAL_GpioPinModeSet(LCD_PORT_DISP_PWR,LCD_PIN_DISP_PWR,palGpioModePushPull,0); #endif // TODO needed? PAL_GpioPinModeSet(LCD_PORT_EXTMODE, LCD_PIN_EXTMODE, palGpioModePushPull,0); PAL_GpioPinModeSet(LCD_PORT_EXTCOMIN,LCD_PIN_EXTCOMIN,palGpioModePushPull,0); #ifdef PAL_TIMER_REPEAT_FUNCTION /* If the platform specifies to use a timer repeat function we should register the DisplayPolarityInverse to be called every second in order to toggle the EXTCOMIN pin at 1Hz. */ status = PAL_TimerRepeat((void(*)(void*)) DisplayPolarityInverse, 0, LS013B7DH03_POLARITY_INVERSION_FREQUENCY); #elif defined POLARITY_INVERSION_EXTCOMIN_PAL_AUTO_TOGGLE /* Setup system (via PAL) to toggle the EXTCOMIN pin every second. */ status = PAL_GpioPinAutoToggle(LCD_PORT_EXTCOMIN, LCD_PIN_EXTCOMIN, LS013B7DH03_POLARITY_INVERSION_FREQUENCY); #else /* System does not support toggling the EXTCOMIN pin. Return error. */ return DISPLAY_EMSTATUS_NOT_SUPPORTED; #endif if (PAL_EMSTATUS_OK != status) { return status; } /* Setup and register the LS013B7DH03 as a DISPLAY device now. */ display.name = SHARP_MEMLCD_DEVICE_NAME; display.colourMode = DISPLAY_COLOUR_MODE_MONOCHROME_INVERSE; display.addressMode = DISPLAY_ADDRESSING_BY_ROWS_ONLY; display.geometry.width = LS013B7DH03_WIDTH; display.geometry.height = LS013B7DH03_HEIGHT; /* stride = pixels + ctrl bytes */ display.geometry.stride = display.geometry.width + LS013B7DH03_CONTROL_BYTES*8; display.pDisplayPowerOn = DisplayEnable; #ifdef PIXEL_MATRIX_ALLOC_SUPPORT display.pPixelMatrixAllocate = PixelMatrixAllocate; display.pPixelMatrixFree = PixelMatrixFree; #else display.pPixelMatrixAllocate = NULL; display.pPixelMatrixFree = NULL; #endif display.pPixelMatrixDraw = PixelMatrixDraw; display.pPixelMatrixClear = PixelMatrixClear; display.pDriverRefresh = DriverRefresh; status = DISPLAY_DeviceRegister (&display); if (DISPLAY_EMSTATUS_OK == status) { /* Turn on display. */ DisplayEnable(&display, true); /* Clear display */ DisplayClear(); } return status; }