Commit 770e8ca9ca20a032777a75c40cb2e23bf8115b77

Authored by lahouass
1 parent 0b8d6477

envoi de données de arduino vers Raspi sur port serie

Showing 1 changed file with 56 additions and 0 deletions   Show diff stats
arduinoToRpi.c 0 → 100644
@@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
  1 +#include <avr/io.h> // for the input/output register
  2 +#include <avr/interrupt.h>
  3 +#include <util/delay.h>
  4 +#include <unistd.h>
  5 +#include <string.h>
  6 +#include <stdlib.h>
  7 +#include <stdio.h>
  8 +
  9 +#define PRESCALER 1024
  10 +#define TIME_SLOT 20
  11 +#define NB_TICK 113
  12 +#define BAUDRATE 103
  13 +
  14 +void send_serial(unsigned char c)
  15 +{
  16 + loop_until_bit_is_set(UCSR0A, UDRE0);
  17 + UDR0 = c;
  18 +}
  19 +
  20 +void send_msg(void){
  21 + char msg[] = "Bonjour\r\n";
  22 + while(1){ //nécessaire pour eviter d'executer la tache une seule fois
  23 + int i=0;
  24 + for(i=0; i<strlen(msg); i++){
  25 + send_serial(msg[i]);
  26 + _delay_ms(100);
  27 +
  28 +}
  29 +
  30 +
  31 +void init_serial(void)
  32 +{
  33 + /* ACHTUNG : we suppose UBRR value < 0xff */
  34 + /* Not true in all case */
  35 + uint8_t baudrate = BAUDRATE;
  36 + /* Set baud rate */
  37 + UBRR0H = 0;
  38 + UBRR0L = baudrate;
  39 +
  40 + /* Enable transmitter *///task_led_red();
  41 + //task_send_serial('A');
  42 + UCSR0B = (1<<TXEN0);
  43 +
  44 + /* Set frame format */
  45 + UCSR0C = 0x06;
  46 +
  47 +}
  48 +
  49 +
  50 +int main(void)
  51 +{
  52 + init_serial();
  53 + while(1){
  54 + send_serial('A');
  55 + sleep(3000)}
  56 +}
0 \ No newline at end of file 57 \ No newline at end of file