ActiveMarkers Programas-CCS
ActiveMarkers Programas-CCS
Julio de 2019
1. Wired .................................................................................................................................... 1
2.1. WirelessMain .................................................................................................................... 5
2.2. RF_Connection(1) ............................................................................................................. 8
2.3. RF_Connection(2) ........................................................................................................... 14
2.4. RF1A(1) ........................................................................................................................... 14
2.5. RF1A(2) ........................................................................................................................... 20
Página i
DESARROLLO DE MARCADORES ACTIVOS PARA APLICACIONES DE CAPTURA DE MOVIMIENTO 3D
PROGRAMACIÓN EN CCS DEL SISTEMA CABLEADO 2019
1. Wired
/****************************************************************************/
/* Board: MSP430-CCRF
/* Manufacture: OLIMEX
/* COPYRIGHT (C) 2018
/* Original Program Designed by: Penko Todorov Bozhkov
/* Current Program Designed by: Gorka Corral Malla
/* Module Name: Wired
/* File Name: Wired.c
/* Revision: initial
/* Date: 07.10.2018
/* Built with Code Composer Studio C/C++ Compiler for MSP430
/****************************************************************************/
// Target : CC430F5137
#include <cc430x513x.h>
#include <intrinsics.h>
//Definitions
#define LED_On P1OUT |= 0x01;
#define LED_Off P1OUT &= (~0x01);
#define LED_Togg P1OUT ^= 0x01;
#define LED_Chk (P1IN & 0x01)
unsigned int j = 1;
unsigned int flag = 0;
/****************************************************************************/
/* Function name: delay
/* Parameters
/* Input : p
/* Output : No
/* Action: Simple delay
/****************************************************************************/
/****************************************************************************/
/* Function name: ports_init
/* Ports : P1, P2 and P3
/* Input : P3.0 and P3.4
/* Output : P3.1 and P3.6
/* Action: Initialize all Port's directions and states
/****************************************************************************/
void ports_init(void){
P1OUT = 0x00;
P1DIR = 0x01; // Led out
P3IN = 0x00;
P3OUT &= ~BIT0 & ~BIT1 & ~BIT4 & ~BIT6; //Set directions to 0.
P3DIR &= ~BIT0 & ~BIT4 | BIT1 | BIT6; //Direct inputs and outputs
P3REN = BIT0 | BIT1 | BIT4 | BIT6;
P3SEL &= ~BIT0 & ~BIT1 & ~BIT4 & ~BIT6;
P3DS &= ~BIT0 & ~BIT1 & ~BIT4 & ~BIT6;
/****************************************************************************/
/* Function name: timer1_A3_init
/* Parameters
/* Input : No
/* Output : No
/* Action: Initialize Timer1_A3 operation
/****************************************************************************/
void timer1_A3_init(void){
/****************************************************************************/
/* Function name: init_devices
/* Parameters
/* Action: Initialize all peripherals
/****************************************************************************/
void init_devices(void){
int main(void){
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
init_devices();
while(1){
if(P3IN&BIT4){
TA1CCTL0 = 0x0010; // Timer1_A3 Capture/compare 0 interrupt enable.
TA1CCR0 = 0x0014; // Set TACCR0 value to 5ms
TA1CTL = 0x02D0; // Selected: SMCLK, divider:8, Up mode.
UCSCTL4 = 0000; // XT1CLK clock selected
Switch_On;
LED_On;
while(P3IN&BIT4){
LED_Off;
P3OUT |= BIT6;
}
while(!(P3IN&BIT4)){
if(!(P3IN&BIT0)){
flag = 0;
}
}
Start_Togg;
LED_Off;
while(P3IN&BIT4){;}
}
}
}
/****************************************************************************/
/* Timer1_A3 CC0 interrupt service routine.
/****************************************************************************/
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_Capture_Compare_ISR(void){
if(j){
LED_Togg;
Pulse_Togg;
j=0;
TA1CCR0 = 0x000D; // Set TACCR0 value to 3,2 ms
}
else{
LED_Togg;
Pulse_Togg;
j=1;
TA1CCR0 = 0x0014; // Set TACCR0 value to 5,2 ms
}
}
/****************************************************************************/
2.1. WirelessMain
/****************************************************************************/
/* Board: MSP430-CCRF
/* Manufacture: OLIMEX
/* COPYRIGHT (C) 2011
/* Original Program Designed by: Penko Todorov Bozhkov
/* Current Program Designed by: Gorka Corral Malla
/* Module Name: WirelessMain
/* File Name: WirelessMain.c
/* Revision: initial
/* Date: 07.10.2018
/* Built with Code Composer Studio C/C++ Compiler for MSP430
/****************************************************************************/
// Target : CC430F5137
#include <cc430x513x.h>
#include <intrinsics.h>
#include "RF_Connection.h"
//Definitions
#define LED_ON P1OUT |= 0x01; P1DIR |= 0x01;
#define LED_OFF P1OUT &= (~0x01); P1DIR |= 0x01;
#define LED_Togg P1OUT ^= 0x01; P1DIR |= 0x01;
#define LED_Chk (P1IN & 0x01)
#define timer1_A3_Stop_Mode TA1CTL &= (~0x0030)
#define timer1_A3_Up_Mode TA1CTL |= (0x0010)
/****************************************************************************/
/* Function name: delay
/* Parameters
/* Input : p
/* Output : No
/* Action: Simple delay
/****************************************************************************/
/****************************************************************************/
/* Function name: ports_init (real init in file: RF_Connection.c)
/* Parameters
/* Action: Initialize all Port's directions and states
/****************************************************************************/
void ports_init(void){
P1OUT = 0x00;
P1DIR = 0x01; // Led out
P1REN = 0x00;
P2OUT = 0x00;
P2DIR = 0x00;
P2REN = 0x00;
P3OUT = 0x00;
P3DIR = 0x00;
P3REN = 0x00;
}
/****************************************************************************/
/* Function name: RTC_Clock_init
/* Parameters
/* Input : No
/* Output : No
/* Action: Set up RTC clock operation
/****************************************************************************/
void RTC_Clock_init(void){
P5OUT = 0x00;
//P5DIR = 0x02; // If this is uncommented RTC doesn't work!!!!!!!!!!!!!!!!!! P5DIR register must
be set to 0x00!!!!!!
do{
/****************************************************************************/
/* Function name: timer1_A3_init
/* Parameters
/* Input : No
/* Output : No
/* Action: Initialize Timer1_A3 operation
/****************************************************************************/
/****************************************************************************/
/* Function name: init_devices
/* Parameters
/* Action: Initialize all peripherals
/****************************************************************************/
void init_devices(void){
RF_Connection_Test();
}
}
2.2. RF_Connection(1)
/******************************************************************************
/* File Name: RF_Connection.c
/* Simple RF Link to Toggle Receiver's LED by pressing Transmitter's Button
/* Warning: This RF code example is setup to operate at 868Mhz frequency,
/* which might be out of allowable range of operation in certain countries. Please
/* refer to the appropriate legal sources before performing tests with this code
/* example.
/*
/* This code example can be loaded to 2 MSP430-CCRF devices. Each device will transmit
/* a small packet upon a button pressed. Each device will also toggle its LED upon
/* receiving said packet.
/*
/* The RF packet engine settings specify variable-length-mode with CRC check enabled
/* The RX packet also appends 2 status bytes regarding CRC check, RSSI and LQI info.
/* For specific register settings please refer to the comments for each register in
/* RF1A_REGISTER_CONFIG[] or the CC430x613x User's Guide and the SmartRF Studio
/*
/* All required changes, which enable this code to be portable for MSP430-CCRF,
/* were made by Penko T. Bozhkov -> Olimex LTD
/* All required changes and algorithms for active markers project were made by Gorka
/* Corral Malla
/******************************************************************************/
#include "cc430x513x.h"
#include "HAL/RF1A.h"
#include "HAL/cc430x613x_PMM.h"
#include "RF_Connection.h"
//#define EMISOR
#define RECEPTOR
#ifdef MHZ_915
#include "HAL/RF_config_Olimex/smartrf_CC430F5137_915MHz_38k4Baud.h"
#elif defined MHZ_868
#include "HAL/RF_config_Olimex/smartrf_CC430F5137_868MHz_38k4Baud.h"
#endif
/********************************************************************************
/* Function name: InitWireless_ports
/* Parameters
/* Input : No
/* Output : No
/* Action: Initialize Led and Button directions.
/********************************************************************************
void InitWireless_ports(void){
// Set up LED
P1OUT &= ~BIT0;
P1DIR |= BIT0;
/********************************************************************************
/* Function name: Init_RF
/* Parameters
/* Input : No
/* Output : No
/* Action: Initialize RF radio core.
/********************************************************************************
void Init_RF(void){
/********************************************************************************
/* Function name: RF_Connection_Test
/* Parameters
/* Action: Sync up input camera signal with LEDs activation signal.
/********************************************************************************
void RF_Connection_Test(void){
Init_RF();
while(1){
//P3OUT |= BIT6;
signalReceived = 0;
#ifdef EMISOR
P2IFG = 0;
LED_TOGG;
ReceiveOff();
if(count2 == 80)
{
Transmit( (unsigned char*)TxBuffer, sizeof TxBuffer);
count2 = 0;
}
count2 ++;
//Wait for TX status to be reached before going back to low power mode
//while((Strobe(RF_SNOP) & 0x70) != 0x20);
ReceiveOn();
// LED_TOGG;
//Wait for RX status to be reached
//while((Strobe(RF_SNOP) & 0x70) != 0x10);
packetTransmit = 0;
count2 = 0;
}
#endif
#ifdef RECEPTOR
if(packetReceived) // Process a received packet
{
//char toggle = 1;
LED_TOGG;
// Read the length byte from the FIFO
RxBufferLength = ReadSingleReg( RXBYTES );
if (RxBufferLength != 0){
ReadBurstReg(RF_RXFIFORD, RxBuffer, RxBufferLength);
// Check the packet contents and don't toggle LED if they are different
for(i = 0; i < RxBuffer[0]; i++){
if(1)
{
//delay
//TA1CTL = 0x0004; // Timer1_A3 clear.
/********************************************************************************
/* PORT2, interrupt service routine.
/********************************************************************************
#pragma vector=PORT2_VECTOR
__interrupt void PORT2_ISR(void)
{
switch(__even_in_range(P2IV, 8))
{
case 0: break;
case 2: break; // P2.0 IFG
case 4: break; // P2.1 IFG
case 6: break; // P2.2 IFG
case 8:
P2IE = 0; // Debounce by disabling signal reception
if(P2IN & BIT3){
signalReceived = 1;
}else{
P2IFG = 0;
P2IE |= BIT3;
}
break; // P2.3 IFG
case 10: break; // P2.4 IFG
case 12: break; // P2.5 IFG
case 14: break; // P2.6 IFG
case 16: break; // P2.7 IFG
}
}
/****************************************************************************/
/* Timer1_A3 CC0 interrupt service routine.
/****************************************************************************/
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_Capture_Compare_ISR(void)
{
__delay_cycles(12);
if(j){
PULSE_UP;
j=0;
TA1CCR0 = 0x006F; // Set TACCR0 value to 3,484 ms aprox
}
else{
PULSE_DOWN;
j=1;
TA1CCR0 = 0x00A2; // Set TACCR0 value to 4,920 ms aprox
}
}
2.3. RF_Connection(2)
/****************************************************************************/
/* Manufacture: OLIMEX
/* COPYRIGHT (C) 2011
/* Original Program Designed by: Penko Todorov Bozhkov
/* Current Program Designed by: Gorka Corral Malla
/* Module Name: RF_Connection
/* File Name: RF_Connection.h
/* Revision Identifier: initial
/* Date: 07.10.2018
/****************************************************************************/
#ifndef __RF_Connection_H
#define __RF_Connection_H
#endif //_RF_Connection_H
2.4. RF1A(1)
#include "RF1A.h"
#include "cc430x513x.h"
// ##########################################################
// This definitions and delay_RF were added by Penko Bozhkov
// ##########################################################
#define TXtoIDLE_Time 10 // TX to IDLE, no calibration: ~1us => 0.3us *10 = 3us
#define RXtoIDLE_Time 2 // RX to IDLE, no calibration: ~0.1us => 0.3*2 = 0.6us
#define IDLEtoRX_Time 300 // IDLE to RX, no calibration: 75.1us => 0.3*300 = 90us
/****************************************************************************/
/* Function name: delay_RF
/* Parameters
/* Input : p
/* Output : No
/* Action: Simple delay
/****************************************************************************/
return statusByte;
}
return data_out;
}
__no_operation();
}
void ReadBurstReg(unsigned char addr, unsigned char *buffer, unsigned char count)
{
unsigned int i;
void WriteBurstReg(unsigned char addr, unsigned char *buffer, unsigned char count)
{
// Write Burst works wordwise not bytewise - known errata
unsigned char i;
while (!(RF1AIFCTL1 & RFINSTRIFG)); // Wait for the Radio to be ready for next instruction
RF1AINSTRW = ((addr | RF_REGWR)<<8 ) + buffer[0]; // Send address + Instruction
valueRead = RF1ADOUT1B;
}
while( !(RF1AIFCTL1 & RFDOUTIFG));
valueRead = RF1ADOUTB;
}
}
void ReceiveOn(void)
{
RF1AIFG &= ~BIT4; // Clear a pending interrupt
RF1AIE |= BIT4; // Enable the interrupt
void ReceiveOff(void)
{
RF1AIE &= ~BIT4; // Disable RX interrupts
RF1AIFG &= ~BIT4; // Clear pending IFG
{
switch(__even_in_range(RF1AIFERRV,8))
{
case 0: break; // No error
case 2: // Low core voltage error
P1OUT &= ~BIT0; // 00 = on LED's [D2,D1]
P3OUT &= ~BIT6;
__no_operation();
break;
case 4: // Operand Error
P1OUT |= BIT0; // 01 = on LED's [D2,D1]
P3OUT &= ~BIT6;
__no_operation();
break;
case 6: // Output data not available error
P1OUT &= ~BIT0; // 10 = on LED's [D2,D1]
P3OUT |= BIT6;
__no_operation();
break;
case 8: // Operand overwrite error
P1OUT |= BIT0; // 11 = on LED's [D2,D1]
P3OUT |= BIT6;
__no_operation();
break;
}
}
#pragma vector=CC1101_VECTOR
__interrupt void CC1101_ISR(void)
{
switch(__even_in_range(RF1AIV,32)) // Prioritizing Radio Core Interrupts
{
2.5. RF1A(2)
/* ------------------------------------------------------------------------------------------------
* Defines
* ------------------------------------------------------------------------------------------------
*/
//#define SELECT_MHZ_FOR_OPERATION 1
#define MHZ_868 1 // Select either 868 or 915MHz
//#define MHZ_915 1
#ifdef SELECT_MHZ_FOR_OPERATION
#error: "Please define frequency of operation in RF1A.h"
#endif