void enableProgramMode( ) { // drive reset high initially to stop flickering drivePin( B, AVRISP_PIN_RESET, high ); output_init( B, AVRISP_PIN_RESET ); // initialize SPI spiMaster_init( spiMaster_clockDiv64 ); // sink device into reset state delay_ms( 50 ); drivePin( B, AVRISP_PIN_RESET, low ); // enter prog mode (manually to check) spiMaster_transmit( 0xAC ); spiMaster_transmit( 0x53 ); spiMaster_transmit( 0x00 ); ubyte verify = spiMaster_receive( ); spiMaster_transmit( 0x00 ); if ( verify != 0x53 ) { statusLed_red( ); uart_putc( AVRISP_RESP_UNKNOWN ); return; } LED_on( ); uart_putc( BYTE_CR ); // done! }
static void spi_init( void ) { spiMaster_init( &spiMaster, 0, PIN_SCLK, PIN_MOSI, PIN_MISO ); }