Created
January 17, 2013 06:46
-
-
Save ossicode/4554203 to your computer and use it in GitHub Desktop.
MSP430F2132 ADC10 polling ADC10IFG version ok
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* aclkuart.c | |
* | |
* Created on: 2012. 12. 19. | |
* Author: OSSI | |
*/ | |
#include "aclkuart.h" | |
static volatile uint8_t uart_rx_flag = 0; | |
static volatile uint8_t rx_byte = '\0'; | |
// Low-Frequency Baud Rate Mode | |
// read chapter 15.3.10 of msp430x2xxx user's guide for baud rate generation | |
void uart_setup_9600(void) | |
{ | |
P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD, No need to set IO direction | |
UCA0CTL1 |= UCSSEL_1; // CLK = ACLK | |
UCA0BR0 = 0x03; // 3 = INT(3.41), 32.768kHz/9600 = 3.41 | |
UCA0BR1 = 0x00; // | |
UCA0MCTL = UCBRS1 + UCBRS0; // Modulation UCBRSx = 3 = round(0.41 * 8) | |
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** | |
} | |
void uart_setup_4800(void) | |
{ | |
P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD, No need to set IO direction | |
UCA0CTL1 |= UCSSEL_1; // CLK = ACLK | |
UCA0BR0 = 0x06; // 6 = INT(6.83), 32.768kHz/4800 = 6.83 | |
UCA0BR1 = 0x00; // | |
UCA0MCTL = UCBRS2 + UCBRS1 + UCBRS0; // Modulation UCBRSx = 7 = round(0.83 * 8) | |
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** | |
} | |
void uart_init(void) | |
{ | |
IE2 |= UCA0RXIE; // default: Enable USCI_A0 RX interrupt | |
IE2 &= ~UCA0TXIE; // default: Disable USCI_A0 TX interrupt | |
} | |
void i2c_set_rxFlag(void) | |
{ | |
} | |
void i2c_clear_rxFlag(void) | |
{ | |
} | |
uint8_t i2c_rx_ready(void) | |
{ | |
return 0; | |
} | |
void uart_set_rxFlag(void) | |
{ | |
uart_rx_flag = 1; | |
} | |
void uart_clear_rxFlag(void) | |
{ | |
uart_rx_flag = 0; | |
} | |
uint8_t uart_rx_ready(void) | |
{ | |
if(uart_rx_flag) | |
{ | |
return 1; | |
} | |
else | |
{ | |
return 0; | |
} | |
} | |
uint8_t uart_get_byte(void) | |
{ | |
// return only you have available data from uart, NOT i2c | |
return rx_byte; | |
} | |
/** | |
* Sends a single byte out through UART | |
**/ | |
void uart_send_byte(unsigned char byte) | |
{ | |
// we're not going to change this to avoid infinite loop as we only use printf() for debugging purpose. | |
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? | |
UCA0TXBUF = byte; // TX -> RXed character | |
} | |
void puts(char *s) { | |
char c; | |
// Loops through each character in string 's' | |
while (c = *s++) { | |
uart_send_byte(c); | |
} | |
} | |
/** | |
* puts() is used by printf() to display or send a character. This function | |
* determines where printf prints to. For this case it sends a character | |
* out over UART. | |
**/ | |
void putc(unsigned b) { | |
uart_send_byte(b); | |
} | |
// USCI A0/B0 Transmit ISR | |
#pragma vector=USCIAB0TX_VECTOR | |
__interrupt void USCI0TX_ISR(void) | |
{ | |
IE2 &= ~UCA0TXIE; // Disable USCI_A0 TX interrupt | |
} | |
// USCI A0/B0 Receive ISR | |
#pragma vector=USCIAB0RX_VECTOR | |
__interrupt void USCI0RX_ISR(void) | |
{ | |
// TODO: I2C and UART handle at the same time | |
rx_byte = UCA0RXBUF; // Get the received character | |
// gps (uart) | |
uart_set_rxFlag(); | |
__bic_SR_register_on_exit(LPM3_bits); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* aclkuart.h | |
* | |
* Created on: 2012. 12. 19. | |
* Author: OSSI | |
*/ | |
#ifndef ACLKUART_H_ | |
#define ACLKUART_H_ | |
#include "ossibeacon.h" | |
void uart_setup_4800(void); | |
void uart_setup_9600(void); | |
void uart_init(void); | |
void uart_set_rxFlag(void); | |
void uart_clear_rxFlag(void); | |
uint8_t uart_rx_ready(void); | |
void i2c_set_rxFlag(void); | |
void i2c_clear_rxFlag(void); | |
uint8_t i2c_rx_ready(void); | |
uint8_t uart_get_byte(void); | |
void putc(unsigned); | |
void puts(char *); | |
#endif /* ACLKUART_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* adc.c | |
* | |
* Created on: 2012. 12. 27. | |
* Author: OSSI | |
*/ | |
#include "adc10.h" | |
void adc10_portSetup(uint8_t ports) | |
{ | |
ASSERT(ports <= 0xFF); | |
// reset ports | |
ADC10AE0 = ports; // set input for pin P2.0 , P2.1, no need to set directions | |
} | |
/* | |
* single channel single conversion only setting | |
*/ | |
void adc10_init(uint8_t clockSourceSelect, uint8_t clockSourceDivider, uint16_t clockCycleHoldCount) | |
{ | |
ASSERT(clockSourceSelect <= ADC10_CLOCKSOURCE_SMCLK); | |
ASSERT(clockSourceDivider <= ADC10_CLOCKDIVIDER_8); | |
ASSERT(clockCycleHoldCount <= ADC10_CYCLEHOLD_64_CYCLES); | |
// make sure clear ENC to set registers | |
ADC10CTL0 &= ~ENC; | |
// Turn OFF ADC10 Module & Clear Interrupt Registers | |
ADC10CTL0 &= ~(ADC10ON + ENC + ADC10SC + ADC10IE + ADC10IFG); // ADC10ON, sampling rate = ACLK * 16 | |
// Reset and Set ADC10 Control 1 | |
// Using ADC10_SAMPLEHOLDSOURCE_SC only | |
ADC10CTL1 = ADC10_SAMPLEHOLDSOURCE_SC + clockSourceSelect + clockSourceDivider; | |
//Reset and Set ADC10 Control 0 | |
ADC10CTL0 = clockCycleHoldCount; | |
} | |
/* | |
* we limit adc10_setVolReference() function to 2 options: | |
* 1. Vr+: VCC, Vr-: VSS / SREFx: 000 | |
* 2. Vr+: Vref+ , Vr-: VSS / SREFx: 001 | |
* for Vref+ reference voltage setting, we use: | |
* ADC10SR = 0 | |
* REFOUT = 0 | |
* REFBIRST = 0 | |
* REF2_5V = 1 (2.5V internal Reference Voltage) | |
* REFON = 1 | |
*/ | |
void adc10_setVolReference(uint16_t refVoltageSourceSelect) | |
{ | |
ASSERT(refVoltageSourceSelect <= ADC10_REF_VREF_VSS); | |
// clear ENC to set registers | |
ADC10CTL0 &= ~ENC; | |
// reset voltage reference settings | |
// clear SREFx bits | |
ADC10CTL0 &= 0x1FFF; | |
// clear rest of the reference settings | |
ADC10CTL0 &= ~(ADC10SR + REFOUT + REFBURST + REF2_5V + REFON); | |
if(refVoltageSourceSelect == ADC10_REF_VCC_VSS) | |
{ | |
ADC10CTL0 |= ADC10_REF_VCC_VSS; | |
} | |
else | |
{ | |
ADC10CTL0 |= (ADC10_REF_VREF_VSS + REF2_5V + REFON); | |
volatile uint8_t i; | |
for(i = 0; i < 17; i++) | |
{ | |
__delay_cycles(7372); | |
} | |
} | |
} | |
void adc10_offInternalVolReference(void) | |
{ | |
// clear ENC to set registers | |
ADC10CTL0 &= ~ENC; | |
ADC10CTL0 &= ~(ADC10SR + REFOUT + REFBURST + REF2_5V + REFON); | |
} | |
/* | |
* single channel / single conversion | |
* param: channelSelect ranges from 0~11 | |
* | |
*/ | |
uint16_t adc10_readChannel(uint8_t channelSelect) | |
{ | |
ASSERT(inputSourceSelect <= 11); | |
uint16_t adc10Channel = 0;; | |
uint16_t adc10Value = 0; | |
// convert channelSelect to set register | |
adc10Channel = (adc10Channel | channelSelect) << 12; | |
adc10Channel = (adc10Channel & 0xF000); | |
// clear ENC to set registers | |
ADC10CTL0 &= ~ENC; | |
// reset input channel and conversion sequence mode | |
ADC10CTL1 &= 0x0FF9; | |
// set input channel | |
ADC10CTL1 |= adc10Channel; | |
// turn adc10 on | |
ADC10CTL0|= ADC10ON; | |
// clear IFG Before Starting Conversion | |
ADC10CTL0 &= ~ADC10IFG; | |
ADC10CTL0 |= ENC; | |
// set to start conversion | |
ADC10CTL0 |= ADC10SC; | |
// wait adc10 to complete the conversion | |
while((ADC10CTL0 & ADC10IFG)==0); | |
adc10Value = ADC10MEM; | |
// clear ENC when ADC10 is not busy | |
while(ADC10CTL0 &ADC10BUSY); | |
// clear IFG after the Conversion | |
ADC10CTL0 &= ~ENC; | |
ADC10CTL0 &= ~ADC10IFG; | |
return adc10Value; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* adc10.h | |
* | |
* Created on: 2012. 12. 27. | |
* Author: OSSI | |
*/ | |
#ifndef ADC10_H_ | |
#define ADC10_H_ | |
#include "ossibeacon.h" | |
#define ADC10_PIN_2_0 (BIT0) | |
#define ADC10_PIN_2_1 (BIT1) | |
#define ADC10_PIN_2_2 (BIT2) | |
#define ADC10_PIN_2_3 (BIT3) | |
#define ADC10_PIN_2_4 (BIT4) | |
#define ADC10_PIN_3_0 (BIT5) | |
#define ADC10_PIN_3_6 (BIT6) | |
#define ADC10_PIN_3_7 (BIT7) | |
#define ADC10_SAMPLEHOLDSOURCE_SC (SHS_0) | |
//#define ADC10_SAMPLEHOLDSOURCE_1 (SHS_1) | |
//#define ADC10_SAMPLEHOLDSOURCE_2 (SHS_2) | |
//#define ADC10_SAMPLEHOLDSOURCE_3 (SHS_3) | |
#define ADC10_CLOCKSOURCE_ADC10OSC (ADC10SSEL_0) | |
#define ADC10_CLOCKSOURCE_ACLK (ADC10SSEL_1) | |
#define ADC10_CLOCKSOURCE_MCLK (ADC10SSEL_2) | |
#define ADC10_CLOCKSOURCE_SMCLK (ADC10SSEL_3) | |
#define ADC10_CYCLEHOLD_4_CYCLES (ADC10SHT_0) | |
#define ADC10_CYCLEHOLD_8_CYCLES (ADC10SHT_1) | |
#define ADC10_CYCLEHOLD_16_CYCLES (ADC10SHT_2) | |
#define ADC10_CYCLEHOLD_64_CYCLES (ADC10SHT_3) | |
#define ADC10_INPUT_A0 (INCH_0) | |
#define ADC10_INPUT_A1 (INCH_1) | |
#define ADC10_INPUT_A2 (INCH_2) | |
#define ADC10_INPUT_A3 (INCH_3) | |
#define ADC10_INPUT_A4 (INCH_4) | |
#define ADC10_INPUT_A5 (INCH_5) | |
#define ADC10_INPUT_A6 (INCH_6) | |
#define ADC10_INPUT_A7 (INCH_7) | |
#define ADC10_INPUT_VREF_POS (INCH_8) //TODO: what is this? | |
#define ADC10_INPUT_VREF_NEG (INCH_9) //TODO: what is this? | |
#define ADC10_INPUT_TEMPSENSOR (INCH_10) | |
#define ADC10_INPUT_VMID (INCH_11) | |
//#define ADC10_INPUT_VMID (INCH_12) | |
//#define ADC10_INPUT_VMID (INCH_13) | |
//#define ADC10_INPUT_VMID (INCH_14) | |
//#define ADC10_INPUT_VMID (INCH_15) | |
#define ADC10_CLOCKDIVIDER_1 (ADC10DIV_0) | |
#define ADC10_CLOCKDIVIDER_2 (ADC10DIV_1) | |
#define ADC10_CLOCKDIVIDER_3 (ADC10DIV_2) | |
#define ADC10_CLOCKDIVIDER_4 (ADC10DIV_3) | |
#define ADC10_CLOCKDIVIDER_5 (ADC10DIV_4) | |
#define ADC10_CLOCKDIVIDER_6 (ADC10DIV_5) | |
#define ADC10_CLOCKDIVIDER_7 (ADC10DIV_6) | |
#define ADC10_CLOCKDIVIDER_8 (ADC10DIV_7) | |
#define ADC10_REF_VCC_VSS (SREF_0) | |
#define ADC10_REF_VREF_VSS (SREF_1) | |
#define ADC10_SINGLECHANNEL (CONSEQ_0) | |
//#define ADC10_SEQOFCHANNELS (CONSEQ_1) | |
//#define ADC10_REPEATED_SINGLECHANNEL (CONSEQ_2) | |
//#define ADC10_REPEATED_SEQOFCHANNELS (CONSEQ_3) | |
void adc10_portSetup(uint8_t ports); | |
// call adc12_init() one time in the beginning | |
void adc10_init(uint8_t clockSourceSelect, uint8_t clockSourceDivider, uint16_t clockCycleHoldCount); | |
void adc10_setVolReference(uint16_t refVoltageSourceSelect); | |
// adc12_end() turns off internal reference | |
// as the reference is not automatically power down | |
// and turns off adc12 module to save power | |
void adc10_offInternalVolReference(void); | |
// returns the value | |
// single channel single conversion mode | |
uint16_t adc10_readChannel(uint8_t channelSelect); | |
#endif /* ADC10_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* clock.c | |
* | |
* Created on: 2013. 1. 16. | |
* Author: OSSI | |
*/ | |
#include "clock.h" | |
// main clock will be shared via system | |
static volatile uint8_t clockMode; | |
uint8_t clock_getMode(void) | |
{ | |
return clockMode; | |
} | |
uint8_t clock_setup(void) | |
{ | |
// after POR: MCLK = SMCLK = DCO ~ 1.2MHz | |
// set DCO speed to calibrated 8MHz | |
// NO VLOCLK use | |
BCSCTL1 = CALBC1_8MHZ; | |
DCOCTL = CALDCO_8MHZ; | |
// TODO: Capacitor setting for ACLK | |
return CLOCK_DCO_LFXT1; | |
} | |
void clock_dividerSetup(uint8_t MCLKDividerSelect, uint8_t SMCLKDividerSelect, uint8_t ACLKDividerSelect) | |
{ | |
// reset divider first | |
// reset ACLK divider | |
BCSCTL1 &= 0xCF; // Clear BIT5 and BIT4 | |
// select ACLK Divider | |
BCSCTL1 |= ACLKDividerSelect; | |
// reset MCLK, SMCLK divider | |
BCSCTL2 &= 0x00; // Clear BIT5,BIT4, BIT2, BIT1 and reset as 2132 only use DCO | |
// select MCLK Divider | |
BCSCTL2 |= MCLKDividerSelect; | |
// select SMCLK Divider | |
BCSCTL2 |= SMCLKDividerSelect; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* clock.h | |
* | |
* Created on: 2013. 1. 16. | |
* Author: OSSI | |
*/ | |
/* Clock setting for OSSI MSP430F2132 | |
* | |
* default: CLOCK_DCO_LFXT1 | |
* DCO Calibrated 8MHz | |
* LFXT1 Low Power Mode: 32.768 kHz | |
* MCLK = DCOCLK / SMCLK = DCOCLK / ACLK = LFXT1 | |
* | |
* TODO: LFXT1 to VLO switching? | |
* | |
*/ | |
#ifndef CLOCK_H_ | |
#define CLOCK_H_ | |
#include "msp430x21x2.h" | |
#include "ossitypes.h" | |
#include "debug.h" | |
#define CLOCK_DCO_LFXT1 (1) | |
#define MCLK_DIVIDED_BY_1 DIVM_0 /* MCLK Divider 0: /1 */ | |
#define MCLK_DIVIDED_BY_2 DIVM_1 /* MCLK Divider 1: /2 */ | |
#define MCLK_DIVIDED_BY_4 DIVM_2 /* MCLK Divider 2: /4 */ | |
#define MCLK_DIVIDED_BY_8 DIVM_3 /* MCLK Divider 3: /8 */ | |
#define SMCLK_DIVIDED_BY_1 DIVS_0 /* SMCLK Divider 0: /1 */ | |
#define SMCLK_DIVIDED_BY_2 DIVS_1 /* SMCLK Divider 1: /2 */ | |
#define SMCLK_DIVIDED_BY_4 DIVS_2 /* SMCLK Divider 2: /4 */ | |
#define SMCLK_DIVIDED_BY_8 DIVS_3 /* SMCLK Divider 3: /8 */ | |
#define ACLK_DIVIDED_BY_1 DIVA_0 /* ACLK Divider 0: /1 */ | |
#define ACLK_DIVIDED_BY_2 DIVA_1 /* ACLK Divider 1: /2 */ | |
#define ACLK_DIVIDED_BY_4 DIVA_2 /* ACLK Divider 2: /4 */ | |
#define ACLK_DIVIDED_BY_8 DIVA_3 /* ACLK Divider 3: /8 */ | |
uint8_t clock_getMode(void); | |
uint8_t clock_setup(void); | |
void clock_dividerSetup(uint8_t MCLKDividerSelect, uint8_t SMCLKDividerSelect, uint8_t ACLKDividerSelect); | |
#endif /* CLOCK_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* --COPYRIGHT--,BSD | |
* Copyright (c) 2012, Texas Instruments Incorporated | |
* All rights reserved. | |
* | |
* Redistribution and use in source and binary forms, with or without | |
* modification, are permitted provided that the following conditions | |
* are met: | |
* | |
* * Redistributions of source code must retain the above copyright | |
* notice, this list of conditions and the following disclaimer. | |
* | |
* * Redistributions in binary form must reproduce the above copyright | |
* notice, this list of conditions and the following disclaimer in the | |
* documentation and/or other materials provided with the distribution. | |
* | |
* * Neither the name of Texas Instruments Incorporated nor the names of | |
* its contributors may be used to endorse or promote products derived | |
* from this software without specific prior written permission. | |
* | |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
* --/COPYRIGHT--*/ | |
//***************************************************************************** | |
// | |
//debug.h - Macros for assisting debug of the driver library. | |
// | |
// | |
//This is part of revision 0001 of the MSP430 Peripheral Driver Library. | |
// | |
//***************************************************************************** | |
#ifndef __DEBUG_H__ | |
#define __DEBUG_H__ | |
//***************************************************************************** | |
// | |
//Prototype for the function that is called when an invalid argument is passed | |
//to an API. This is only used when doing a DEBUG build. | |
// | |
//***************************************************************************** | |
extern void __error__ (char *pcFilename, unsigned long ulLine); | |
//***************************************************************************** | |
// | |
//The ASSERT macro, which does the actual assertion checking. Typically, this | |
//will be for procedure arguments. | |
// | |
//***************************************************************************** | |
#ifdef DEBUG | |
#define ASSERT(expr) { \ | |
if (!(expr)) \ | |
{ \ | |
__error__(__FILE__, __LINE__); \ | |
} \ | |
} | |
#else | |
#define ASSERT(expr) | |
#endif | |
#endif //__DEBUG_H__ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* main.c | |
*/ | |
#include "ossibeacon.h" | |
#include "printf.h" | |
#include "adc10.h" | |
uint16_t adcValueVccRef[7]={0}; | |
uint16_t adcValueIntRef[7]={0}; | |
void main(void) { | |
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer | |
// default: MCLK = SMCLK = DCO ~ 1.2MHz | |
clock_setup(); | |
clock_dividerSetup(MCLK_DIVIDED_BY_1, SMCLK_DIVIDED_BY_1, ACLK_DIVIDED_BY_1); | |
// general IO init | |
// TODO: set unused pins!!! | |
P1DIR = 0xFF & ~(BIT1+BIT2); // ADF7012 TXCLK output is high. Beware!!! | |
P1OUT = 0x00; | |
P3DIR = 0xFF & ~(BIT1+BIT2+BIT3+BIT5); | |
P3OUT = 0x00; | |
P2DIR = 0xFF & ~(BIT0+BIT1+BIT5); | |
P2OUT = 0x00; | |
adc10_portSetup(ADC10_PIN_2_0 + ADC10_PIN_2_1); | |
TA0CTL = TASSEL_1 + MC_2; // ACLK, contmode | |
uart_setup_9600(); | |
uart_init(); | |
IO_DIRECTION(LED,OUTPUT); | |
IO_SET(LED,LOW); | |
adc10_init(ADC10_CLOCKSOURCE_SMCLK,ADC10_CLOCKDIVIDER_8,ADC10_CYCLEHOLD_16_CYCLES); | |
TA0CCTL0 |= CCIE; | |
_EINT(); | |
while(1) | |
{ | |
volatile uint8_t i; | |
_NOP(); | |
// Vref = VCC | |
adc10_setVolReference(ADC10_REF_VCC_VSS); | |
for (i = 0; i < 2;i++) | |
{ | |
adcValueVccRef[i] = adc10_readChannel(i); | |
// Convert the value to 0 ~ 3300 mV (3300/2^10 = 3.222) *2 (Voltage divider is present) | |
adcValueVccRef[i] = (uint16_t)(6.444 * adcValueVccRef[i]); | |
} | |
// Vref = Internal Ref 2.5V | |
adc10_setVolReference(ADC10_REF_VREF_VSS); | |
for (i = 0; i < 2;i++) | |
{ | |
adcValueIntRef[i] = adc10_readChannel(i); | |
// Convert the value to 0 ~ 2500 mV (2500/2^10 = 2.441) * 2 (Voltage divider is present) | |
adcValueIntRef[i] = (uint16_t)(4.882 * adcValueIntRef[i]); | |
} | |
// When we use internal reference, | |
// Make sure you turn it off to save power | |
adc10_offInternalVolReference(); | |
printf("** OSSI-1 ADC10 TEST **\r\n"); | |
printf("VBUS VREF=VCC: %u\r\n", adcValueVccRef[0]); | |
printf("VCC VREF=VCC: %u\r\n", adcValueVccRef[1]); | |
printf("VBUS VREF=INT: %u\r\n", adcValueIntRef[0]); | |
printf("VCC VREF=INT: %u\r\n", adcValueIntRef[1]); | |
printf("\r\n"); | |
__bis_SR_register(LPM3_bits+GIE); | |
} | |
} | |
#pragma vector = TIMER0_A0_VECTOR | |
__interrupt void TA0_ISR(void) | |
{ | |
__bic_SR_register_on_exit(LPM3_bits); // Exit LPM0 | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* ossibeacon.h | |
* | |
* Created on: 2012. 12. 22. | |
* Author: OSSI | |
*/ | |
#ifndef OSSIBEACON_H_ | |
#define OSSIBEACON_H_ | |
#include "msp430x21x2.h" | |
#include "debug.h" | |
#include "clock.h" | |
#include "system.h" | |
#include "ossitypes.h" | |
#include "util.h" | |
#endif /* OSSIBEACON_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* ossitypes.h | |
* | |
* Created on: 2012. 12. 22. | |
* Author: OSSI | |
*/ | |
#ifndef OSSITYPES_H_ | |
#define OSSITYPES_H_ | |
typedef unsigned char uint8_t; | |
typedef signed char int8_t; | |
typedef unsigned short int uint16_t; | |
typedef signed short int int16_t; | |
typedef unsigned long int uint32_t; | |
typedef signed long int int32_t; | |
#endif /* OSSITYPES_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************** | |
* Reusable MSP430 printf() | |
* | |
* Description: This printf function was written by oPossum and originally | |
* posted on the 43oh.com forums. For more information on this | |
* code, please see the link below. | |
* | |
* http://www.43oh.com/forum/viewtopic.php?f=10&t=1732 | |
* | |
* A big thanks to oPossum for sharing such great code! | |
* | |
* Author: oPossum | |
* Source: http://www.43oh.com/forum/viewtopic.php?f=10&t=1732 | |
* Date: 10-17-11 | |
* | |
* Note: This comment section was written by Nicholas J. Conn on 06-07-2012 | |
* for use on NJC's MSP430 LaunchPad Blog. | |
******************************************************************************/ | |
/* | |
* printf.c | |
* | |
* Created on: 2012. 12. 19. | |
* Author: OSSI | |
*/ | |
#include "printf.h" | |
static const unsigned long dv[] = { | |
// 4294967296 // 32 bit unsigned max | |
1000000000,// +0 | |
100000000, // +1 | |
10000000, // +2 | |
1000000, // +3 | |
100000, // +4 | |
// 65535 // 16 bit unsigned max | |
10000, // +5 | |
1000, // +6 | |
100, // +7 | |
10, // +8 | |
1, // +9 | |
}; | |
static void xtoa(unsigned long x, const unsigned long *dp) { | |
char c; | |
unsigned long d; | |
if (x) { | |
while (x < *dp) | |
++dp; | |
do { | |
d = *dp++; | |
c = '0'; | |
while (x >= d) | |
++c, x -= d; | |
putc(c); | |
} while (!(d & 1)); | |
} else | |
putc('0'); | |
} | |
static void puth(unsigned n) { | |
static const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', | |
'9', 'A', 'B', 'C', 'D', 'E', 'F' }; | |
putc(hex[n & 15]); | |
} | |
void printf(char *format, ...) | |
{ | |
char c; | |
int i; | |
long n; | |
va_list a; | |
va_start(a, format); | |
while(c = *format++) { | |
if(c == '%') { | |
switch(c = *format++) { | |
case 's': // String | |
puts(va_arg(a, char*)); | |
break; | |
case 'c':// Char | |
putc(va_arg(a, char)); | |
break; | |
case 'i':// 16 bit Integer | |
case 'u':// 16 bit Unsigned | |
i = va_arg(a, int); | |
if(c == 'i' && i < 0) i = -i, putc('-'); | |
xtoa((unsigned)i, dv + 5); | |
break; | |
case 'l':// 32 bit Long | |
case 'n':// 32 bit uNsigned loNg | |
n = va_arg(a, long); | |
if(c == 'l' && n < 0) n = -n, putc('-'); | |
xtoa((unsigned long)n, dv); | |
break; | |
case 'x':// 16 bit heXadecimal | |
i = va_arg(a, int); | |
puth(i >> 12); | |
puth(i >> 8); | |
puth(i >> 4); | |
puth(i); | |
break; | |
case 0: return; | |
default: goto bad_fmt; | |
} | |
} else | |
bad_fmt: putc(c); | |
} | |
va_end(a); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* printf.h | |
* | |
* Created on: 2012. 12. 19. | |
* Author: OSSI | |
*/ | |
#ifndef PRINTF_H_ | |
#define PRINTF_H_ | |
#include "stdarg.h" | |
#include "aclkuart.h" | |
void printf(char *, ...); | |
#endif /* PRINTF_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* setup2132.c | |
* | |
* Created on: 2012. 12. 19. | |
* Author: OSSI | |
*/ | |
#include "system.h" | |
void int_wdt_disable(void) | |
{ | |
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer | |
} | |
void IO_setup(void) | |
{ | |
// general IO init | |
// TODO: set unused pins!!! | |
IO_DIRECTION(LED,OUTPUT); | |
IO_SET(LED,LOW); | |
} | |
void ext_wdt_setup(void) | |
{ | |
IO_DIRECTION(EXTWDT,OUTPUT); | |
} | |
void ext_wdt_rst(void) | |
{ | |
//LOW-HIGH-LOW | |
IO_SET(EXTWDT,LOW); | |
delay_ms(1); | |
IO_SET(EXTWDT,HIGH); | |
delay_ms(1); | |
IO_SET(EXTWDT,LOW); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* setup2132.h | |
* | |
* Created on: 2012. 12. 19. | |
* Author: OSSI | |
*/ | |
#ifndef SETUP2132_H_ | |
#define SETUP2132_H_ | |
#include "msp430x21x2.h" | |
#include "ossitypes.h" | |
#include "util.h" | |
// System IO Define | |
#define LED_PORT 3 | |
#define LED_PIN 0 | |
#define EXTWDT_PORT 2 | |
#define EXTWDT_PIN 2 | |
void int_wdt_disable(void); | |
void IO_setup(void); | |
void ext_wdt_setup(void); | |
void ext_wdt_rst(void); | |
#endif /* SETUP2132_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* util.c | |
* | |
* Created on: 2012. 12. 19. | |
* Author: OSSI | |
*/ | |
#include "util.h" | |
void delay_ms(uint16_t delay) | |
{ | |
volatile uint16_t i; | |
for (i=0; i<delay;i++) | |
{ | |
__delay_cycles(8000); // @ DCO 8MHz | |
} | |
} | |
void min_max(uint8_t min, uint8_t max, uint8_t value) | |
{ | |
if (value <= min) | |
{ | |
value = min; | |
} | |
if (value > max) | |
{ | |
value = max; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* global.h | |
* | |
* Created on: 2012. 6. 3. | |
* Author: donghee | |
*/ | |
#ifndef GLOBAL_H_ | |
#define GLOBAL_H_ | |
#include "ossitypes.h" | |
// Macros for turning on and off the LEDs (for testing only) | |
enum {FALSE = 0, TRUE = 1}; | |
#define _BV(bit) (1<<(bit)) | |
//macros for IO config (with preprocessor abuse) | |
#define st(x) do{x} while(__LINE__ == -1) | |
enum IoState {LOW = 0, HIGH = 1, TOGGLE = 2}; | |
#define IO_SET(name,val) _IO_SET(name##_PORT,name##_PIN,val) | |
#define _IO_SET(port,pin,val) st(__IO_SET(port,pin,val);) | |
#define __IO_SET(port,pin,val) if (val == TOGGLE)\ | |
{\ | |
st((P##port##OUT ^= _BV(pin)););\ | |
}\ | |
else if (val == HIGH)\ | |
{\ | |
st((P##port##OUT |= _BV(pin)););\ | |
}\ | |
else\ | |
{\ | |
st((P##port##OUT &= ~_BV(pin)););\ | |
} | |
enum IoDirection {INPUT = 0, OUTPUT = 1}; | |
#define IO_DIRECTION(name,dir) _IO_DIRECTION(name##_PORT,name##_PIN,dir) | |
#define _IO_DIRECTION(port,pin,dir) st(__IO_DIRECTION(port,pin,dir);) | |
#define __IO_DIRECTION(port,pin,dir) if (dir)\ | |
{\ | |
st((P##port##DIR |= _BV(pin)););\ | |
}\ | |
else\ | |
{\ | |
st((P##port##DIR &= ~_BV(pin)););\ | |
} | |
void delay_ms(uint16_t delay); | |
void min_max(uint8_t min, uint8_t max, uint8_t value); | |
#endif /* GLOBAL_H_ */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment