Commit 7d8fe198 authored by Martin Enriquez's avatar Martin Enriquez

En los ejemplos del año anterior se reescribe la inicializacion para que tenga...

En los ejemplos del año anterior se reescribe la inicializacion para que tenga una lectura mas amigable
parent 79d710ae
......@@ -8,3 +8,16 @@ Command-line arguments: -data /home/martin/Documentos/Digitales III/proyecto-di
!ENTRY org.eclipse.cdt.core 1 0 2015-11-30 11:26:06.252
!MESSAGE Indexed 'Remoto-con-8' (3 sources, 24 headers) in 2,56 sec: 596 declarations; 1.656 references; 1 unresolved inclusions; 1 syntax errors; 52 unresolved names (2,3 %)
!SESSION 2015-11-30 11:43:41.568 -----------------------------------------------
eclipse.buildId=4.5.1.M20150904-0015
java.version=1.7.0_79
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=es_AR
Framework arguments: -product org.eclipse.epp.package.cpp.product
Command-line arguments: -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.cpp.product
!ENTRY org.eclipse.cdt.core 1 0 2015-11-30 11:45:23.394
!MESSAGE Indexed 'modulo_on_off' (3 sources, 21 headers) in 1,86 sec: 435 declarations; 1.325 references; 1 unresolved inclusions; 1 syntax errors; 49 unresolved names (2,7 %)
!ENTRY org.eclipse.cdt.core 1 0 2015-11-30 11:45:47.099
!MESSAGE Indexed 'modulo_luces' (3 sources, 21 headers) in 0,74 sec: 443 declarations; 1.330 references; 1 unresolved inclusions; 1 syntax errors; 49 unresolved names (2,7 %)
*** SESSION nov. 30, 2015 11:22:04.27 ------------------------------------------
*** SESSION nov. 30, 2015 11:43:54.78 ------------------------------------------
11:27:53 **** Incremental Build of configuration Release for project Remoto-con-8 ****
11:44:16 **** Incremental Build of configuration Release for project Remoto-con-8 ****
make all
Building file: ../nrf24l01.c
Invoking: AVR Compiler
avr-gcc -Wall -Os -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega8 -DF_CPU=8000000UL -MMD -MP -MF"nrf24l01.d" -MT"nrf24l01.o" -c -o "nrf24l01.o" "../nrf24l01.c"
Finished building: ../nrf24l01.c
Building target: Remoto-con-8.elf
Invoking: AVR C Linker
avr-gcc -Wl,-Map,Remoto-con-8.map -mmcu=atmega8 -o "Remoto-con-8.elf" ./main.o ./mcu.o ./nrf24l01.o
Finished building target: Remoto-con-8.elf
Invoking: AVR Create Extended Listing
avr-objdump -h -S Remoto-con-8.elf >"Remoto-con-8.lss"
Finished building: Remoto-con-8.lss
Create Flash image (ihex format)
avr-objcopy -R .eeprom -R .fuse -R .lock -R .signature -O ihex Remoto-con-8.elf "Remoto-con-8.hex"
Finished building: Remoto-con-8.hex
Create eeprom image (ihex format)
avr-objcopy -j .eeprom --no-change-warnings --change-section-lma .eeprom=0 -O ihex Remoto-con-8.elf "Remoto-con-8.eep"
Finished building: Remoto-con-8.eep
Invoking: Print Size
avr-size --format=avr --mcu=atmega8 Remoto-con-8.elf
AVR Memory Usage
......@@ -38,5 +16,5 @@ Data: 14 bytes (1.4% Full)
Finished building: sizedummy
11:27:54 Build Finished (took 695ms)
11:44:16 Build Finished (took 97ms)
11:27:53 **** Incremental Build of configuration Release for project Remoto-con-8 ****
12:07:24 **** Incremental Build of configuration Release for project modulo_on_off ****
make all
Building file: ../nrf24l01.c
Building file: ../mcu.c
Invoking: AVR Compiler
avr-gcc -Wall -Os -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega8 -DF_CPU=8000000UL -MMD -MP -MF"nrf24l01.d" -MT"nrf24l01.o" -c -o "nrf24l01.o" "../nrf24l01.c"
Finished building: ../nrf24l01.c
avr-gcc -Wall -Os -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega8 -DF_CPU=8000000UL -MMD -MP -MF"mcu.d" -MT"mcu.o" -c -o "mcu.o" "../mcu.c"
Finished building: ../mcu.c
Building target: Remoto-con-8.elf
Building target: modulo_on_off.elf
Invoking: AVR C Linker
avr-gcc -Wl,-Map,Remoto-con-8.map -mmcu=atmega8 -o "Remoto-con-8.elf" ./main.o ./mcu.o ./nrf24l01.o
Finished building target: Remoto-con-8.elf
avr-gcc -Wl,-Map,modulo_on_off.map -mmcu=atmega8 -o "modulo_on_off.elf" ./main.o ./mcu.o ./nrf24l01.o
Finished building target: modulo_on_off.elf
Invoking: AVR Create Extended Listing
avr-objdump -h -S Remoto-con-8.elf >"Remoto-con-8.lss"
Finished building: Remoto-con-8.lss
avr-objdump -h -S modulo_on_off.elf >"modulo_on_off.lss"
Finished building: modulo_on_off.lss
Create Flash image (ihex format)
avr-objcopy -R .eeprom -R .fuse -R .lock -R .signature -O ihex Remoto-con-8.elf "Remoto-con-8.hex"
Finished building: Remoto-con-8.hex
avr-objcopy -R .eeprom -R .fuse -R .lock -R .signature -O ihex modulo_on_off.elf "modulo_on_off.hex"
Finished building: modulo_on_off.hex
Create eeprom image (ihex format)
avr-objcopy -j .eeprom --no-change-warnings --change-section-lma .eeprom=0 -O ihex Remoto-con-8.elf "Remoto-con-8.eep"
Finished building: Remoto-con-8.eep
avr-objcopy -j .eeprom --no-change-warnings --change-section-lma .eeprom=0 -O ihex modulo_on_off.elf "modulo_on_off.eep"
Finished building: modulo_on_off.eep
Invoking: Print Size
avr-size --format=avr --mcu=atmega8 Remoto-con-8.elf
avr-size --format=avr --mcu=atmega8 modulo_on_off.elf
AVR Memory Usage
----------------
Device: atmega8
Program: 1490 bytes (18.2% Full)
Program: 1378 bytes (16.8% Full)
(.text + .data + .bootloader)
Data: 14 bytes (1.4% Full)
Data: 15 bytes (1.5% Full)
(.data + .bss + .noinit)
......
11:56:24 **** Incremental Build of configuration Release for project modulo_luces ****
make all
Invoking: Print Size
avr-size --format=avr --mcu=atmega8 modulo_luces.elf
AVR Memory Usage
----------------
Device: atmega8
Program: 1374 bytes (16.8% Full)
(.text + .data + .bootloader)
Data: 18 bytes (1.8% Full)
(.data + .bss + .noinit)
Finished building: sizedummy
11:56:25 Build Finished (took 163ms)
12:07:24 **** Incremental Build of configuration Release for project modulo_on_off ****
make all
Building file: ../mcu.c
Invoking: AVR Compiler
avr-gcc -Wall -Os -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega8 -DF_CPU=8000000UL -MMD -MP -MF"mcu.d" -MT"mcu.o" -c -o "mcu.o" "../mcu.c"
Finished building: ../mcu.c
Building target: modulo_on_off.elf
Invoking: AVR C Linker
avr-gcc -Wl,-Map,modulo_on_off.map -mmcu=atmega8 -o "modulo_on_off.elf" ./main.o ./mcu.o ./nrf24l01.o
Finished building target: modulo_on_off.elf
Invoking: AVR Create Extended Listing
avr-objdump -h -S modulo_on_off.elf >"modulo_on_off.lss"
Finished building: modulo_on_off.lss
Create Flash image (ihex format)
avr-objcopy -R .eeprom -R .fuse -R .lock -R .signature -O ihex modulo_on_off.elf "modulo_on_off.hex"
Finished building: modulo_on_off.hex
Create eeprom image (ihex format)
avr-objcopy -j .eeprom --no-change-warnings --change-section-lma .eeprom=0 -O ihex modulo_on_off.elf "modulo_on_off.eep"
Finished building: modulo_on_off.eep
Invoking: Print Size
avr-size --format=avr --mcu=atmega8 modulo_on_off.elf
AVR Memory Usage
----------------
Device: atmega8
Program: 1378 bytes (16.8% Full)
(.text + .data + .bootloader)
Data: 15 bytes (1.5% Full)
(.data + .bss + .noinit)
Finished building: sizedummy
12:07:24 Build Finished (took 199ms)
/*
* main.c
*
* Created on: 25/1/2015
* Author: Enrquez Martn | Leandro Lanzieri
*/
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "nrf24l01.h"
#include "mcu.h"
#include "hardware.h"
#include "comunicacion.h"
uint8_t *data;
volatile boton_t boton;
int main(void)
{
init_megazord();
LED = 1;
int i;
// El mirco est vivo... EST VIVOOO! (?)
for(i = 0; i < 10; i++)
{
LED ^= 1; // Toggle LED
_delay_ms(200);
}
Set_frec(FREC_ON_OFF);
while(1)
{
if (demora_tim1 >= 20)
{
reset();
Modo_RX();
CE = 1;
demora_tim1 = 0;
}
_delay_ms(500);
data[0] = RELE_TOGGLE;
Modo_TX();
transmit_payload(data);
reset();
demora_tx = 0;
/*
leer_botones();
switch(boton)
{
case LUZ:
Set_frec(FREC_LUCES);
_delay_ms(20);
data[0] = LUCES_TOGGLE;
Modo_TX();
transmit_payload(data);
reset();
demora_tx = 0;
break;
case ENCHUFE:
Set_frec(FREC_ON_OFF);
_delay_ms(20);
data[0] = RELE_TOGGLE;
Modo_TX();
transmit_payload(data);
reset();
demora_tx = 0;
break;
case INCREMENTAR:
LED ^= 1;
Set_frec(FREC_LUCES);
_delay_ms(20);
data[0] = LUCES_AUMENTAR;
Modo_TX();
transmit_payload(data);
reset();
demora_tx = 0;
break;
case DECREMENTAR:
Set_frec(FREC_LUCES);
_delay_ms(20);
data[0] = LUCES_DISMINUIR;
Modo_TX();
transmit_payload(data);
reset();
demora_tx = 0;
break;
case NINGUNO:
default:
break;
}*/
}
return 0;
}
ISR(INT0_vect)
{
cli();
CE = 0; // CE bajo
data = WriteToNrf(R, R_RX_PAYLOAD, data, dataLen); //Leo el mensaje
data[0] = 0;
sei();
CE = 1; // CE alto
}
/*
* mcu.c
*
* Created on: 5/2/2015
* Author: Martn
*/
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "nrf24l01.h"
#include "mcu.h"
#include "hardware.h"
volatile unsigned int demora_tim1=0;
volatile unsigned int demora_tx=0;
volatile unsigned int tiempo_tx=0;
void init_megazord(void)
{
LED_DDR |= (1 << LED_PIN); //LED SALIDA
RELE_DDR |= (1 << RELE_PIN); //RELE SALIDA
init_TMR();
init_SPI();
nrf24L01_init();
init_INT();
sei();
}
void init_TMR(void)
{
//Timer1 para SystemTick
TCCR1A = 0x00;
TCNT1H = 0xFC;
TCNT1L = 0x17; //Tiempo para hacer que el timer cuente durante 1 mSeg
TIMSK = 0x04; //Habilitar interrupcion por ovf del timer1
TCCR1B = 0x02; //ARRANCA EL TIMER 1 CON PRESCALER DE OOOOOCHO
}
void init_SPI(void)
{
// Pongo SCK, MOSI, CSN y CE como salidas
SCK_DDR |= (1 << SCK_PIN);
MOSI_DDR |= (1 << MOSI_PIN);
CE_DDR |= (1 << CE_PIN);
CSN_DDR |= (1 << CSN_PIN);
// Habilito SPI y pongo el micro como master
SPCR |= (1 << SPE) | (1 << MSTR) | (1 << SPR0);
CSN = 1;
CE = 1;
}
void init_INT(void)
{
DDRD &= ~(1 << DDD2); // INT0 (PD2) como entradas
MCUCR |= (1 << ISC01); // INT0 e INT1 en falling edge
MCUCR &= ~(1 << ISC00);
GICR |= (1 << INT0); //Habilito la interrupcin
}
/*
* Delay_ms
* Brief: Funcion de retardo
*/
void delay_ms(unsigned int tiempo)
{
demora_tim1 = 0;
while(demora_tim1 < tiempo );
}
/*
* nRF24L01.c
*
* Created on: 24/08/2014
* Autor: Andrs, Oscar / Corbaln Damin, / Fanelli, Javier
* Brief: Comunicacin inalmrbica con nrF24L01+
*
*
*/
#include "nRF24L01.h"
#include "hardware.h"
#include "comunicacion.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
char WriteByteSPI(unsigned char cData)
{
SPDR = cData;
while(!(SPSR & (1<<SPIF)));
return SPDR;
}
void PCINT12_interrupt_init(void)
{
DDRD &= ~(1 << DDD2); // INT0 (PD2)como entrada
MCUCR |= (1 << ISC01); // INT0 en falling edge
MCUCR &= ~(1 << ISC00);
MCUCR &= ~(1 << ISC10); // INT0 en falling edge
GICR |= (1 << INT0); //Habilito la interrupcin
}
uint8_t GetReg(uint8_t reg) //Funcin para leer un registro reg
{
_delay_us(10);
CSN = 0;
_delay_us(10);
WriteByteSPI(R_REGISTER + reg);
_delay_us(10);
reg = WriteByteSPI(NOP);
_delay_us(10);
CSN = 1;
return reg;
}
uint8_t *WriteToNrf(uint8_t ReadWrite, uint8_t reg, uint8_t *val, uint8_t antVal) //Funcin de lectura o escritura
//"W o R" (Escribir o leer), "reg" (el registro), "*val" (valor a escribir) & "antVal" (cantidad de enteros a escribir)
{
cli();
if (ReadWrite == W)
{
reg = W_REGISTER + reg;
}
static uint8_t ret[dataLen];
_delay_us(10);
CSN = 0;
_delay_us(10);
WriteByteSPI(reg);
_delay_us(10);
int i;
for(i=0; i<antVal; i++)
{
if (ReadWrite == R && reg != W_TX_PAYLOAD)
{
ret[i]=WriteByteSPI(NOP);
_delay_us(10);
}
else
{
WriteByteSPI(val[i]);
_delay_us(10);
}
}
CSN = 1;
sei();
return ret;
}
void nrf24L01_init(void)
{
//_delay_ms(100);
uint8_t val[5];
val[0]=0x03;
WriteToNrf(W, EN_AA, val, 1); //Habilito auto ACK en P0
val[0]=0x2F;
WriteToNrf(W, SETUP_RETR, val, 1); //Configuro la retransmisin con un ARD=705useg y ARC=15
val[0]=0x03;
WriteToNrf(W, EN_RXADDR, val, 1); //Habilito el P0
val[0]=0x03;
WriteToNrf(W, SETUP_AW, val, 1); //Seteo 5 bytes de longitud de direccin
val[0]=FREC_ON_OFF;
WriteToNrf(W, RF_CH, val, 1); //Seteo el canal de frecuencia 2,520 GHz
val[0]=0x26;
WriteToNrf(W, RF_SETUP, val, 1); //Seteo vel de transmisin en 250Kb/s y potencia en 0dBm
int i;
for(i=0; i<5; i++)
{
val[i]=0x12; //Nmero de direccin
}
WriteToNrf(W, RX_ADDR_P0, val, 5); //Cargo la direccin del RX
for(i=0; i<5; i++)
{
val[i]=0x13; //Nmero de direccin
}
WriteToNrf(W, RX_ADDR_P1, val, 5); //Cargo la direccin del RX
for(i=0; i<5; i++)
{
val[i]=0x12; //Nmero de direccin
}
WriteToNrf(W, TX_ADDR, val, 5); //Cargo la direccin del TX
// Configuracin de capacidad de la carga til (payload) - Esttica de 1 - 32 bytes
val[0]=dataLen;
WriteToNrf(W, RX_PW_P0, val, 1);
val[0]=dataLen;
WriteToNrf(W, RX_PW_P1, val, 1);
val[0]=0x1F; //Configuracin de modo, TX=7E - RX=1F
WriteToNrf(W, CONFIG, val, 1);
//_delay_ms(100);
}
void reset(void)
{
_delay_us(10);
CSN = 0;
_delay_us(10);
WriteByteSPI(W_REGISTER + STATUS);
_delay_us(10);
WriteByteSPI(0b01110000);
_delay_us(10);
CSN = 1;
}
void receive_payload(void)
{
sei();
CE = 1;
_delay_ms(1000);
CE = 0;
cli();
}
void transmit_payload(uint8_t * W_buff)
{
WriteToNrf(R, FLUSH_TX, W_buff, 0);
WriteToNrf(R, W_TX_PAYLOAD, W_buff, dataLen);
sei();
_delay_ms(10);
CE = 1;
_delay_ms(1);
CE = 0;
_delay_ms(10);
}
void Modo_TX(void)
{
uint8_t val[5];
val[0]=0x7E; //Configuracin de modo, TX=1E - RX=1F
WriteToNrf(W, CONFIG, val, 1);
CE=0;
}
void Modo_RX(void)
{
uint8_t val[5];
val[0]=0x1F; //Configuracin de modo, TX=1E - RX=1F
WriteToNrf(W, CONFIG, val, 1);
}
void Set_frec(uint8_t frecuencia)
{
uint8_t val[5];
val[0]= frecuencia;
WriteToNrf(W, RF_CH, val, 1);
}
void Cambio_Pipe(unsigned char direccion)
{
uint8_t val[5];
int i;
for(i=0; i<5; i++)
{
val[i]=direccion; //Nmero de direccin
}
WriteToNrf(W, TX_ADDR, val, 5); //Cargo la direccin del TX
}
/*
* main.c
*
* Created on: 5/2/2015
* Author: Martín
*/
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "nrf24l01.h"
#include "mcu.h"
#include "hardware.h"
#include "comunicacion.h"
volatile unsigned char rele = 0, enviar_estado = 0;
uint8_t *data;
int main(void)
{
init_megazord();
int i;
for (i = 0; i < 11; i++)
{
LED ^= 1;
_delay_ms(200);
}