123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- #include "ch.h"
- #include "hal.h"
- #include "chprintf.h"
- BaseSequentialStream *chp = (BaseSequentialStream *) &SD1;
- uint16_t cpt = 0;
- char txbuf[] = "ABCD";
- void spiCallback(SPIDriver *spip) {
- chnWrite(&SD1, (const uint8_t *)"*", 1);
- spip->txbuf = 0;
- };
- static const SPIConfig spiCfg = {
- spiCallback,
- IOPORT2,
- 7,
- SPI_PRESCALER_DIV4_gc,
- SPI_MODE_0_gc,
- true,
- false,
- false,
- SPI_INTLVL_OFF_gc,
- };
- static THD_WORKING_AREA(waThread1, 32);
- static THD_FUNCTION(Thread1, arg) {
- (void)arg;
- chRegSetThreadName("Blinker");
- while (true) {
- palClearPad(IOPORT5, PORTE_LED);
- chThdSleepMilliseconds(1000);
- palSetPad(IOPORT5, PORTE_LED);
- chThdSleepMilliseconds(100);
- }
- }
- int main(void) {
-
- halInit();
- chSysInit();
- palClearPad(IOPORT5, PORTE_LED);
-
- palSetPadMode(IOPORT3, PIN3, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(IOPORT3, PIN2, PAL_MODE_INPUT_PULLUP);
-
- sdStart(&SD1, NULL);
-
- spiStart(&SPID1, &spiCfg);
-
- chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
-
- chprintf(chp, "AVR SPI program testhal program example.\r\n");
- while (TRUE) {
- chprintf(chp, "Hello world %i.\r\n", cpt++);
- spiSelect(&SPID1);
- spiStartSend(&SPID1, 4, txbuf);
- spiUnselect(&SPID1);
- chThdSleepMilliseconds(1000);
- }
- return 0;
- }
|