main.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #include "ch.h"
  14. #include "hal.h"
  15. static THD_WORKING_AREA(waThread1, 32);
  16. static THD_FUNCTION(Thread1, arg) {
  17. (void)arg;
  18. chRegSetThreadName("Blinker");
  19. while (true) {
  20. palTogglePad(IOPORT2, PORTB_LED1);
  21. chThdSleepMilliseconds(1000);
  22. }
  23. }
  24. /*
  25. * Application entry point.
  26. */
  27. int main(void) {
  28. uint8_t tx[3];
  29. uint8_t rx[2];
  30. /*
  31. * System initializations.
  32. * - HAL initialization, this also initializes the configured device drivers
  33. * and performs the board-specific initializations.
  34. * - Kernel initialization, the main() function becomes a thread and the
  35. * RTOS is active.
  36. */
  37. halInit();
  38. chSysInit();
  39. palClearPad(IOPORT2, PORTB_LED1);
  40. i2cStart(&I2CD1, NULL);
  41. /*
  42. * Starts the LED blinker thread.
  43. */
  44. chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  45. while (TRUE) {
  46. /* Write value 0xAA to address 0 on the 24C64 */
  47. tx[0] = 0x00;
  48. tx[1] = 0x00;
  49. tx[2] = 0xAA;
  50. i2cMasterTransmit(&I2CD1, 0x50, tx, 3, NULL, 0);
  51. /* Send address 0 and read value at that location */
  52. i2cMasterTransmit(&I2CD1, 0x50, tx, 2, rx, 1);
  53. chThdSleepMilliseconds(1000);
  54. }
  55. }