1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| /********************************************************
Test I2C
********************************************************/
#include "framework.h"
#include "gpio.h"
#include "apptimer.h"
#include "i2cpacket.h"
#include "i2c.h"
#include <tos.h>
#include <sliders.h>
#define SLIDER0 GPIO_3 //Commutateurs
#define SLIDER1 GPIO_4
#define SLIDER2 GPIO_5
#define VTE GPIO_7
#define LEDROUGE GPIO_0 // Pin connected to LED.
#define LEDJAUNE GPIO_1
#define LEDVERT GPIO_2
static enum
{
IDLE,
ENVOI,
} etat = IDLE;
// Functions' declarations.
void mainLoop(); // Main loop.
void allumerLed(bool result);
void timerFired(); // Blink timer handler.
/********************************************************
Users entry.
********************************************************/
void fw_userEntry(FW_ResetReason_t resetReason)
{
static bool on_vert=0;
// Initialize the pin connected to the LED.
gpio_setConfig(LEDVERT, GPIO_OUTPUT);
gpio_setConfig(VTE, GPIO_OUTPUT);
gpio_setState(VTE,1); //active mon I2C
result_t res_open;
I2CMode_t com;
com.clockrate=I2C_CLOCK_RATE_250;
res_open = i2cpacket_open(&com); //ouvre le port I2C
if(res_open==SUCCESS) { on_vert=1; gpio_setState(LEDVERT, on_vert);}
else{on_vert=0; gpio_setState(LEDVERT, on_vert);}
// start interruption
{
int handle;
handle = appTimer_open(timerFired);
appTimer_start(handle, TIMER_REPEAT_MODE, 500);
}
// Start main loop.
fw_setUserLoop(100, mainLoop);
}
void allumerLed(bool result)
{
gpio_setState(LEDROUGE, 1);
}
/********************************************************
Main loop.
********************************************************/
void mainLoop()
{
result_t res_write;
uint8_t id = 0x20;
uint8_t in_length = 2;
// uint8_t data[2];
uint16_t data1 = 0x32AF;
// data[0]=50;//0x32;
// data[1]=175;//0xAF;
// data[2]=0x55;
switch (etat)
{
case IDLE:
break;
case ENVOI:
res_write = i2cpacket_write(id, in_length, (uint8_t*)(&data1), allumerLed); // ou (uint8_t*)(&data), allumerLed); //&data, allumerLed
etat = IDLE;
break;
}
}
/********************************************************
Blink timer handler.
********************************************************/
void timerFired() //Routine d'interruption
{
static int top=0;
if(top==0) {gpio_setState(LEDROUGE, 0); top=1;}
else {etat = ENVOI; top=0;}
} |
Partager