Informe
Informe
3.
4.
Realizar una comunicacin va Bluetooth o WiFi para interactuar mediante una interfaz grfica
con el envo y recepcin de datos mediante
esta.
Protocolo de comunicacin IC
Al tener uno o ms dispositivos conectados a bus, es
necesario respetar un protocolo, debido a esto se
genera el concepto de MAESTRO y ESCLAVOS. Siendo
los maestros los nicos que pueden iniciar la
comunicacin.
PALABRAS CLAVE
SPI, IC, PWM, tiempo, frecuencia, Bluetooth, Distancia,
transmisor, receptor, acelermetro, brjula.
MATERIALES Y METODOS
Elementos y equipo
Motorreductores.
Bateras de 12 y 9 voltios.
Piones.
MARCO TEORICO
BUS IC (Inter Integrated Circuit)
Es un estndar que facilita la comunicacin entre
microcontroladores y otros dispositivos que solo requiere
de dos seales. Se caracteriza por ser una
comunicacin de tipo serial y sincrnica en donde una
de sus seales marca el tiempo (SCL) y la otra
intercambia los datos(SDA).
Arquitectura de Software
Buscando ampliar la compatibilidad de los dispositivos
Bluetooth, los dispositivos que se apegan al estndar
utilizan como interfaz entre el dispositivo anfitrin
.
(laptop, telfono celular, etc) y el dispositivo Bluetooth
como tal (chip Bluetooth) una interfaz denominada HCI
(Host Controller Interface).
Ocurre
la
transmisin
de
datos.
Active:
Protocolo de Conexin
.
pero no aporta ningn dato sobre
componentes vectoriales de campo.
Acelermetro
Los acelermetros son dispositivos que miden la
aceleracin, que es la tasa de cambio de la velocidad de
un objeto. Esto se mide en metros por segundo al
cuadrado (m/s) o en las fuerzas G (g).
las
2. Diseo de GUI(Matlab).
Botn de inicio.
Botn de inicio
Casillas de introduccin de datos:
Velocidad
Posicin.
Casillas de visualizacin de datos:
Velocidad
Posicin
Tiempo.
Botn de aceleracin.
Botn de frenado.
Cuadro para grafica de inclinacin.
Velocidad
Para esta casilla se us una comunicacin bluetooth que
enva los datos ingresados en el cuadro de texto (edit1)
de la velocidad a la cual debe ir el vehculo por medio de
una variable (V)
.
(STM32F4) de la posicin del vehculo mediante una
variable tipo chart (P) y es visualizada en forma de
string en el cuadro de texto(edit6)
Posicin.
Para esta casilla se us una comunicacin bluetooth que
enva los datos ingresados en el cuadro de texto (edit2)
de la posicin que debe seguir el vehculo por medio de
una variable (P).
Tiempo
Para esta casilla se us una funcin (Tic - Toc) que
muestra el tiempo transcurrido en el cual el carro
comienza su trayecto y cuando termina mediante el
cuadro de texto (text6). Este cuadro no tiene una funcin
especfica y responde ante los cambios de los botones
de acelerar y frenar.
Botn de aceleracin
Para este botn de estado se configuro una funcin en
la cual, al cambiar a un estado lgico alto (1) se inicializa
la funcin Tic que indica el inicio del conteo del tiempo a
su vez pone un set al botn de frenado en un estado
lgico bajo (0). Como funcin principal este botn indica
el encendido de los motores mediante un (1) enviado por
bluetooth a la tarjeta.
.
3.3 Programacin Brjula.
3.4 Programacin Bluetooth.
CONCLUSIONES
Bibliografa
.
]
[2
]
[3
]
[4
]
[5
]
[6
]
[7
]
ergio_garcia_garcia_2013.pdf?sequence=1. [ltimo
acceso: 29 05 2016].
[8 Ardumania, Ardumania, [En lnea]. Available:
] http://www.ardumania.es/brujula-digital-hmc5883l/.
[ltimo acceso: 29 05 2016].
[9 5. Electronica, 5Hertz Electronica, [En lnea].
] Available: http://5hertz.com/tutoriales/?p=228. [ltimo
acceso: 30 05 2016].
ANEXOS
PROGRAMA ACELERMETRO
#define GPIO_D_ADDress 0x40020C00
#define offset_ODR 0x14
#define GPIO_A_ADDress 0x40020000
#define alias 0x42000000
#define bit_band 0x40000000
#define offset_bit ((GPIO_D_ADDress+offset_ODR)-bit_band)
//Led naranja
#define pin1 13
#define bit_band_adress1 (alias + (offset_bit*0x20) + (pin1*0x4))
#define naranja (*((volatile unsigned long *) bit_band_adress1))
//Led azul
#define pin3 15
#define bit_band_adress3 (alias + (offset_bit*0x20) + (pin3*0x4))
#define azul (*((volatile unsigned long *) bit_band_adress3))
int8_t x_data1,x_data2,y_data1,y_data2;
int16_t x_dat,y_dat,x,y,rcx,rax,rcy,ray;
int USART_DIV=0,Mantissa=0,Fraction=0x07;
(1<<0);
(1<<1);
(1<<2);
(1<<3);
(1<<4);
10
break;
break;
break;
break;
break;
//Habilitar puerto A
//Habilitar puerto B
//Habilitar puerto C
//Habilitar puerto D
//Habilitar puerto E
.
}
/*
FUNCIONES ACELEROMETRO
*/
//Tx SPI param: adress, data
void SPI_Tx(uint8_t adress, uint8_t data){
GPIO_ResetBits(GPIOE,GPIO_Pin_3);
while(!SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE));
SPI_I2S_SendData(SPI1,adress);
while(!SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_RXNE));
SPI_I2S_ReceiveData(SPI1);
while(!SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE));
SPI_I2S_SendData(SPI1,data);
while(!SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_RXNE));
SPI_I2S_ReceiveData(SPI1);
GPIO_SetBits(GPIOE,GPIO_Pin_3);
}
//Rx SPI param: adress, return data
uint8_t SPI_Rx(uint8_t adress){
GPIO_ResetBits(GPIOE,GPIO_Pin_3);
adress=0x80|adress;
while(!SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE));
SPI_I2S_SendData(SPI1,adress);
while(!SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_RXNE));
SPI_I2S_ReceiveData(SPI1);
while(!SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE));
SPI_I2S_SendData(SPI1,0x00);
while(!SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_RXNE));
GPIO_SetBits(GPIOE,GPIO_Pin_3);
return SPI_I2S_ReceiveData(SPI1);
}
void Acelerometro(void){
asm{
/*A continuacion se realiza la secuencia para que enciandan los respectivos
leds*/
MOV x_dat,x
MOV y_dat,y
bucles:
CMP x,#500
BGE six500
CMP x,#-500
BLE sixno500
CMP y,#500
BGE siy500
CMP y,#-500
BLE siyno500
B sinoxy
six500:
CMP y,#500
BGE sixiy
CMP y,#-500
BLE
sixnoy
B
six
11
sixiy:
MOV
azul,
MOV naranja,#0
B
bucles
#1
MOV
azul,
MOV naranja,#1
B
bucles
#0
MOV
azul,
MOV naranja,#0
B
bucles
#0
sixnoy:
six:
sixno500:
CMP y,#500
BGE sixy500
CMP y,#-500
BLE
sixyno500
B
sinox
sixy500:
MOV
azul,
MOV naranja,#0
B
bucles
#1
sixyno500:
MOV azul,
#0
MOV naranja,#1
B
bucles
sinox:
MOV
azul,
MOV naranja,#0
B
bucles
#0
MOV
azul,
MOV naranja,#0
B
bucles
#1
siy500:
siyno500:
MOV
azul,
MOV naranja,#1
B
bucles
#0
sinoxy:
MOV azul,
#0
MOV naranja,#0
}
}
void Acele_Config(void){
RCC->APB1ENR |=(1<<14);
RCC->APB1ENR |=(1<<15);
RCC->APB2ENR |=(1<<12);
12
.
RCC->APB2ENR |=(1<<13);
RCC->APB2ENR |=(1<<20);
RCC->APB2ENR |=(1<<21);
GPIOD->MODER
= 0x44000000;
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_3;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource5,GPIO_AF_SPI1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource6,GPIO_AF_SPI1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource7,GPIO_AF_SPI1);
SPI_InitTypeDef SPI_InitStruct;
SPI_InitStruct.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_2;
SPI_InitStruct.SPI_Direction=SPI_Direction_2Lines_FullDuplex;
SPI_InitStruct.SPI_Mode=SPI_Mode_Master;
SPI_InitStruct.SPI_DataSize=SPI_DataSize_8b;
SPI_InitStruct.SPI_FirstBit=SPI_FirstBit_MSB;
SPI_InitStruct.SPI_CPOL=SPI_CPOL_High;
SPI_InitStruct.SPI_CPHA=SPI_CPHA_2Edge;
SPI_InitStruct.SPI_NSS=SPI_NSS_Soft|SPI_NSSInternalSoft_Set;
SPI_Init(SPI1,&SPI_InitStruct);
GPIO_SetBits(GPIOE,GPIO_Pin_3);
SPI_Cmd(SPI1,ENABLE);
//Tx SPI param1, param2, ...
SPI_Tx(0x20,0x63);
SPI_Tx(0x24,0x20);
}
void Acele_Sys(void){
x_data1 = SPI_Rx(0x29);
x_data2 = SPI_Rx(0x28);
y_data1 = SPI_Rx(0x2B);
y_data2 = SPI_Rx(0x2A);
asm{
ADD tiempo, #1
MOV x_dat, x_data1
LSL x_dat, x_dat, #8
ADD x_dat, x_data2
13
.
B SiT20cheeck
/*Se toman valores para la media,
cuando eltiempo sea 20 ya se tomaron los 20 datos
y ya se debio realizar la media
*/
SiT20:
/*Sen inicializan los valores para realizar la division*/
MOV rax, x
MOV rcx, #0
MOV ray, y
MOV rcy, #0
B bucle
bucle:
/*Restas iterativas hasta que se cumpla que rax es menor que el tiempo
con esto la division lleara a su fin sin importarnos mucho el residuo*/
SUB rax, tiempo
ADD rcx, #1
CMP rax, tiempo
BGE bucle
MOV x_dat, rcx
B bucle2
bucle2:
/*Restas iterativas hasta que se cumpla que ray es menor que el tiempo
con esto la division lleara a su fin sin importarnos mucho el residuo*/
SUB ray, tiempo
ADD rcy, #1
CMP ray, tiempo
BGE bucle2
MOV y_dat, rcy
MOV tiempo,#0
SiT20cheeck:
CMP tiempo, #100
IT EQ
BEQ SiT20
}
}
PROGRAMA BRUJULA
int main(void){
int Alto=0;
SystemCoreClockUpdate();
//Inicia el contador de tiempo
SysTick_Config( SystemCoreClock/1000 );
Puertos(PA);
//Habilitar puerto A
Puertos(PD);
//Habilitar puerto D
14
Puertos(PE);
//Habilitar puerto E
Acele_Config();
//Configurar Acelerometro
Config_EXTI();
//Configuracipon interrupcin
EXTI_Config(10,0);
//Interrupcin en el puerto A0
Baudrate(9600);
USART_Config();
Configuracion_PWM();
GPIOD->MODER|=
GPIOD->MODER|=
(1<<2*12);
(1<<2*14);
while(1){
if(USART2->DR ==
1){
Alto=10;
USART2->SR='10';
}
if(USART2->DR ==
2){
Alto=20;
USART2->SR='20';
}
if(USART2->DR ==
3){
Alto=30;
USART2->SR='30';
}
if(USART2->DR ==
4){
Alto=40;
USART2->SR='40';
}
if(USART2->DR ==
5){
Alto=50;
USART2->SR='50';
}
if(USART2->DR ==
6){
Alto=60;
USART2->SR='60';
}
if(USART2->DR ==
7){
Alto=70;
USART2->SR='70';
}
if(USART2->DR ==
8){
Alto=80;
USART2->SR='80';
}
if(USART2->DR ==
9){
Alto=90;
USART2->SR='90';
}
if(USART2->DR ==
0){
Alto=100;
USART2->SR='100';
}
15
Parametros(0.035,
500,
14,
Alto);
'V'){
|=
=
(1<<12);
'v';
'G'){
&=
~(1<<12);
'R'){
|=
(1<<14);
'D'){
&=
~(1<<14);
'A'){
|=
|=
(1<<12);
(1<<14);
Acelerometro();
if(USART2->DR ==
GPIOD->ODR
USART2->SR
}
if(USART2->DR ==
GPIOD->ODR
}
if(USART2->DR ==
GPIOD->ODR
}
if(USART2->DR ==
GPIOD->ODR
}
if(USART2->DR ==
GPIOD->ODR
GPIOD->ODR
}
}
}
16