Shield RS232 problème de communication avec Arduino Uno.

Bonjour,

Je suis en stage et pour réaliser mon projet J'ai acheté un Shield RS232 pour un Arduino Uno dans le but de récupérer les valeurs affichées par un appareil.

Le shield RS232 en question : RS232 Shield - DEV-11958 - SparkFun Electronics
Schématique: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Dev/Arduino/Shields/arduino_RS232.pdf
Datasheet : http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Dev/Arduino/Shields/max232.pdf

Je test d'abord la communication entre l'ordinateur et l'arduino équipé du shield rs232 (le programme a été téléversé dans l'arduino avant que le shield ne soit connecté car il occupe les broches TX et RX ce qui empèche la communication par le port USB).

Problèmes:

  • En théorie je devrais pouvoir téléverser un programme depuis le port rs232 de mon ordinateur au Shield rs232, seulement j'ai ce message d'erreur : avrdude: stk500_getsync(): not in sync: resp=0x00

  • En essayant avec le programme présent dans l'arduino Uno je ne reçois pas les informations Serial.print("test par exemple") sur l'hyperterminal, mais les LED RX et TX du Shield RS232 s'allument quand je lui envois un message par l'hyperterminal (le programme renvoit un message par Serial.print lorsqu'il en reçoit un, donc les deux led doivent bien s'allument), cependant mon programme est supposé écrire sur une carte SD les ce qui est reçut en Serial.read, mais elle reste vide.

Le programme en question (un exemple modifié):

/*
  SD card read/write
 
 This example shows how to read and write data to and from an SD card file 	
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 
 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 
 This example code is in the public domain.
 	 
 */
 
#include <SD.h>
char msg;
File myFile;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   Serial.println("commande"); // ordre à l'appareil par le rs232
   while(Serial.available() == 0);
    Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
   pinMode(10, OUTPUT);
   
  if (!SD.begin(4)) {
     Serial.println("initialization failed!");
  }
  
else
 {
   Serial.println("initialization done."); 
}
}
void loop()
{
  
  
  String msg = "";
  Serial.println("#0002Un"); // ordre à l'appareil par le rs232
  while(Serial.available() == 0); // tant qu'il n'y a pas d'informations reçu, le programme n'avance plus.
   if(Serial.available() > 0) // si il y a bien infos reçues
  {
    while(Serial.available() > 0) // tant qu'infos reçues ...;
    {
      msg += char(Serial.read()); // chaque char de Serial.read est ajouté 1 à 1 à string msg
      delay(10); // nécessaire si non ça écrit plus vite que ça n'envoit
                   // relatif au baud rate
  }
    
     Serial.println(msg); // affiche msg
  }

  
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("rs232.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  if (myFile) {
     Serial.print("Writing to rs232.txt...");
    myFile.println(msg);
	// close the file:
    myFile.close();
     Serial.println("done.");
  } 
   else {
     // if the file didn't open, print an error:
       Serial.println("error opening test.txt");
   }
  
  // re-open the file for reading:
   myFile = SD.open("rs232.txt");
   if (myFile) {
      Serial.println("rs232.txt:");
    
     // read from the file until there's nothing else in it:
     while (myFile.available()) {
     	Serial.write(myFile.read());
     }
    // close the file:
     myFile.close();
   } else {
  	// if the file didn't open, print an error:
     Serial.println("error opening test.txt");
  }
}

Des idées sur la raison pour laquelle je n'arrive pas à envoyer/récupérer des données avec le shield rs232 ?

PS:
J'ai aussi essayer ce programme du site Arduino.cc
mais je crois qu'il n'est pas à jour avec la version actuelle d'Arduino:

//Created August 23 2006
//Heather Dewey-Hagborg
//http://www.arduino.cc

#include <ctype.h>

#define bit9600Delay 84  
#define halfBit9600Delay 42
#define bit4800Delay 188 
#define halfBit4800Delay 94 

byte rx = 6;
byte tx = 7;
byte SWval;

void setup() {
  pinMode(rx,INPUT);
  pinMode(tx,OUTPUT);
  digitalWrite(tx,HIGH);
  digitalWrite(13,HIGH); //turn on debugging LED
  SWprint('h');  //debugging hello
  SWprint('i');
  SWprint(10); //carriage return
}

void SWprint(int data)
{
  byte mask;
  //startbit
  digitalWrite(tx,LOW);
  delayMicroseconds(bit9600Delay);
  for (mask = 0x01; mask>0; mask <<= 1) {
    if (data & mask){ // choose bit
     digitalWrite(tx,HIGH); // send 1
    }
    else{
     digitalWrite(tx,LOW); // send 0
    }
    delayMicroseconds(bit9600Delay);
  }
  //stop bit
  digitalWrite(tx, HIGH);
  delayMicroseconds(bit9600Delay);
}

int SWread()
{
  byte val = 0;
  while (digitalRead(rx));
  //wait for start bit
  if (digitalRead(rx) == LOW) {
    delayMicroseconds(halfBit9600Delay);
    for (int offset = 0; offset < 8; offset++) {
     delayMicroseconds(bit9600Delay);
     val |= digitalRead(rx) << offset;
    }
    //wait for stop bit + extra
    delayMicroseconds(bit9600Delay); 
    delayMicroseconds(bit9600Delay);
    return val;
  }
}

void loop()
{
    SWval = SWread(); 
    SWprint(toupper(SWval));
}

WhiteZORA:
...
Problèmes:

  • En théorie je devrais pouvoir téléverser un programme depuis le port rs232 de mon ordinateur au Shield rs232, seulement j'ai ce message d'erreur : avrdude: stk500_getsync(): not in sync: resp=0x00

  • En essayant avec le programme présent dans l'arduino Uno je ne reçois pas les informations Serial.print("test par exemple") sur l'hyperterminal, mais les LED RX et TX du Shield RS232 s'allument quand je lui envois un message par l'hyperterminal (le programme renvoit un message par Serial.print lorsqu'il en reçoit un, donc les deux led doivent bien s'allument), cependant mon programme est supposé écrire sur une carte SD les ce qui est reçut en Serial.read, mais elle reste vide.

Bonjour
pour uploader un programme , il faut gerer le signal DTR aussi au niveau RS232, ce que ne fait pas le shield RS232
si les leds TX et RX du shield s'allument au rythme des evois/receptions c'est que la conversion RS232/TTL fonctionne
test en bouclant TX et RX sur l'arduino pour voir si il y a bien un echo

Merci pour ta réponse !

J'ai donc relier TX et RX, et elles s'allument toutes les secondes (l'écho dont tu parles je suppose), avec le programme dont il est question (le premier de mon premier post sur ce sujet), mais je ne vois pas trop en quoi ça m'avance ^^'