Hi, I'm tryng to make a serial communication between Power Line to create two smart plugs that sharing information about wich relais must be connected regardless the amount of power generating by a Photovoltaic plant.
I wrote a simple program to communicate between two Duemilanove Arduino( implementing the exchange of 2 analog inputs and 4 digital inputs), working at 9600 baud with Easy Transfer library and the sw does what I want.
Now what I want is to use this sw to send datas with Power Line Communication with an Hw base on PLM1 of Ariane Control.
The sw gived by constructor of the shield named Mamba makes a bridge communication between 2 serials (like of 2 PC) as:
[quote]
[color=#7E7E7E]/******************************************************************************************[/color]
[color=#7E7E7E]** LinkSprite Technologies, Inc[/color]
[color=#7E7E7E]* Arduino Powerline Communication Shield Sample Code[/color]
[color=#7E7E7E]* tested from Arduino IDE 1.0.1[/color]
[color=#7E7E7E]* Jingfeng Liu[/color]
[color=#7E7E7E]* jingfeng.liu@linksprite.com[/color]
[color=#7E7E7E]* 6/25/2012[/color]
[color=#7E7E7E] ******************************************************************************************/[/color]
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <avr/interrupt.h>
#include <util/[color=#CC6600]delay[/color].h>
#include [color=#006699]"spi.h"[/color]
#include [color=#006699]"ports.h"[/color]
#include [color=#006699]"plm1.h"[/color]
[color=#CC6600]static[/color] volatile bool uart_tx_flag = [color=#CC6600]false[/color]; [color=#7E7E7E]/* Flag for Tx UART interrupt. */[/color]
[color=#CC6600]static[/color] volatile bool uart_rx_flag = [color=#CC6600]false[/color]; [color=#7E7E7E]/* Flag for Rx UART interrupt. */[/color]
[color=#CC6600]static[/color] uint8_t uart_rx_data; [color=#7E7E7E]/* Rx UART data read. */[/color]
uint8_t rx_packet[PLM_RX_MAX_PACKET_SIZE];
uint8_t rx_length = 0;
uint8_t tx_packet[PLM_TX_MAX_PACKET_SIZE];
uint8_t tx_length = 0;
uint8_t incomingByte = 0; [color=#7E7E7E]// for incoming serial data[/color]
[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()
{
[color=#CC6600]pinMode[/color](MOSI, [color=#006699]OUTPUT[/color]); [color=#7E7E7E]//PIN_OUTPUT(MOSI);[/color]
[color=#CC6600]pinMode[/color](SCK, [color=#006699]OUTPUT[/color]); [color=#7E7E7E]//PIN_OUTPUT(SCK);[/color]
[color=#CC6600]pinMode[/color](nPLM_RESET,[color=#006699]OUTPUT[/color]); [color=#7E7E7E]//PIN_OUTPUT(nPLM_RESET);[/color]
[color=#CC6600]pinMode[/color](PLM_CS, [color=#006699]OUTPUT[/color]); [color=#7E7E7E]//PIN_OUTPUT(PLM_CS);[/color]
[color=#CC6600]pinMode[/color](MISO, [color=#006699]INPUT[/color]); [color=#7E7E7E]//PIN_INPUT(MISO);[/color]
[color=#7E7E7E]/* SPI communication must be initialized before plm1 library. */[/color]
spi_init( SPI_SPEED_F32 );
[color=#7E7E7E]/* Initialization of plm1 library. */[/color]
plm1_init();
[color=#7E7E7E]/* Activate external interrupt 0 for PLM-1 */[/color]
EIFR = 0xFF; [color=#7E7E7E]/* Clear external interrupt flags. */[/color]
EICRA = _BV( ISC00 ) | _BV( ISC01 ); [color=#7E7E7E]/* INT0 activated on a rising edge. */[/color]
EIMSK = _BV( INT0 ); [color=#7E7E7E]/* Enable only external interrupt 0 (PLM). */[/color]
[color=#CC6600][b]Serial[/b][/color].[color=#CC6600]begin[/color](9600); [color=#7E7E7E]// set up Serial library at 9600 bps[/color]
[color=#7E7E7E]/* Activate global interrupts. */[/color]
sei();
}
[color=#CC6600]void[/color]
[color=#CC6600][b]loop[/b][/color]( [color=#CC6600]void[/color] )
{
[color=#7E7E7E]// send data only when you receive data:[/color]
[color=#CC6600]if[/color] ([color=#CC6600][b]Serial[/b][/color].[color=#CC6600]available[/color]() > 0) {
[color=#7E7E7E]// read the incoming byte:[/color]
incomingByte = [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]read[/color]();
plm1_send_data(&incomingByte, 1);
}
[color=#7E7E7E]/* When a packet is received, plm1_receive returns the length of the [/color]
[color=#7E7E7E] * packet and copies the contents of the packet in rx_packet. */[/color]
[color=#CC6600]if[/color]( (rx_length = plm1_receive(rx_packet)) )
{
[color=#CC6600][b]Serial[/b][/color].[color=#CC6600]write[/color]([color=#CC6600]byte[/color](rx_packet[0]));
}
}
[color=#7E7E7E]/* Interrupt Service Routine provenant de la ligne d'interruption du PLM. */[/color]
SIGNAL(INT0_vect)
{
plm1_interrupt();
}
[/quote]
Have someone a suggest to send what I have on the TX pin of Arduino without staying to check the Serial.available() (that means some bits from the PC serial?)
I thougt to create a second serial with the output of what I receive from the other Arduino and then send it to the RX pin (2).
But I can't make an output TX at the same time of the data that I'm receiving...
Thank you everyone.