Quantcast
Channel: MSP low-power microcontrollers
Viewing all articles
Browse latest Browse all 62309

Forum Post: MCP3551

$
0
0
Hello, I am making the interface between the MSP430FG4618 and MCP3551. I am getting a value of 1048573 which is not consistent with the input state + VIN = VCC (+ 5V) and Vin = GND (0V). When VIN + and -Vin = VCC (+ 5V) the value is 2097151 and when VIN + = GND and Vin (0V), the value is 2097151 also !. Would not it be 0? I'm doing something wrong? Already replaces the MCP3551 and is in the same state! The following code: #include "msp430xG46x.h" #include "LCD16x2_Data_Logger.c" #include #include #include #include #define Time_80_ms 2622 unsigned int value; long adcValue; char strADC_Value[12]; void Delay_Timer(unsigned int Delay); //************************************************************************************************************// // Definições dos Pinos de Entrada e Saída do MSP430 do Data Logger // //************************************************************************************************************// void initPORTS(void) { P1IE = (BIT0+BIT1); P1IES = !(BIT0+BIT1); P2DIR |= BIT0+BIT1+BIT2; // P2.2 e P2.1 como saída P2OUT |= BIT0; // Apaga LED1 e LED2 P2OUT &=~ BIT1+BIT2; // Apaga LED1 e LED2 P5DIR |= 0x002; // P5.1 output P3SEL |= 0x0C; // P3.3,2 option select P3DIR |= 0x01; // P3.0 output direction P5DIR = 0x02; // Define P5.1 como Saída P5OUT &=~ 0x02; // Apaga LED4 } //************************************************************************************************************// // Definições e Inicialização do BASIC TIMER para Temporizações do Data Logger // //************************************************************************************************************// void initBT(void) { BTCNT1 = BTCNT2 = 0; BTCTL = BTDIV + BT_fCLK2_DIV128; // Configura o Basic Timer } void Delay_Timer (unsigned int Delay) { TACCTL0 &=~ CCIFG; TACTL = TASSEL_1 + MC_1 + TACLR; TACCR0 = Delay; TACCTL0 = CCIE; __bis_SR_register(LPM3_bits + GIE); } /******************************************************************************* * Function MCP3551_Read * ------------------------------------------------------------------------------ * Overview: Read over SPI ADC value in MCP3551 register * Input: Nothing * Output: ADC Value *******************************************************************************/ long MCP3551_Read() { char ADC_Byte1, ADC_Byte2, ADC_Byte3 = 0; long ADC_Value = 0; P3OUT &=~ 0x01; // Enable MCP3551 CS_pin; Clear(port bit); put low Delay_Timer(Time_80_ms);//__delay_cycles(1000000); // PowerUp Time (min.10us) IFG2 &= ~UCB0RXIFG; // Clear int flag // I get the third byte UCB0TXBUF = 0x00; // Dummy write to start SPI while (!(IFG2 & UCB0RXIFG)); // RXBUF ready? ADC_Byte3 = UCB0RXBUF; // Move value IFG2 &= ~UCB0RXIFG; // Clear int flag // I get the third byte UCB0TXBUF = 0x00; // Dummy write to start SPI while (!(IFG2 & UCB0RXIFG)); // RXBUF ready? ADC_Byte2 = UCB0RXBUF; // Move value IFG2 &= ~UCB0RXIFG; // Clear int flag // I get the third byte UCB0TXBUF = 0x00; // Dummy write to start SPI while (!(IFG2 & UCB0RXIFG)); // RXBUF ready? ADC_Byte1 = UCB0RXBUF; // Move value // enter shutdown (typ.10us) P3OUT |= 0x01; // Disable MCP3551 CS_pin; Set(port bit); put high Delay_Timer(Time_80_ms);//__delay_cycles(100000); // PowerUp Time (min.10us) // store 24 bits in ADC_Value ADC_Value = ADC_Byte3; ADC_Value = (ADC_Value 0) ADC_Value = 3000000; // Vin+ >= Vref ; Vin- = GND // OVL (false) condition else if (ADC_Byte3 == 0x9F && ADC_Byte1 > 0){ ADC_Value = -3000000; // Vin- >= Vref ; Vin+ = GND } else { if ((ADC_Byte3 & 0x20) >> 5) // Bit 21 = 1 ; value is negative ADC_Value = ADC_Value - 4194304; // for 22 bit resolution } return ADC_Value; } void main(void) { volatile unsigned int i; WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer FLL_CTL0 |= XCAP14PF; // Configure load caps // Wait for xtal to stabilize do { IFG1 &= ~OFIFG; // Clear OSCFault flag for (i = 0x47FF; i > 0; i--); // Time for flag to set } while ((IFG1 & OFIFG)); // OSCFault flag still set? initPORTS(); initBT(); UCB0CTL1 |= UCSWRST; UCB0CTL0 |= UCMST+UCSYNC+UCMSB; // 3-pin, 8-bit SPI mstr, MSb 1st UCB0CTL1 |= UCSSEL_2; // SMCLK UCB0BR0 = 0x02; UCB0BR1 = 0; UCB0CTL1 &=~ UCSWRST; // **Initialize USCI state machine** P5OUT &=~ 0x02; // Liga o LCD16X2 InitLCD(); LCDClear(); LCDPrintString("Testando..."); __delay_cycles(1000000); LCDSetPosition(1,0); LCDPrintString("Display LCD16X2"); __delay_cycles(1000000); LCDClear(); //P7OUT = 0; //P5OUT |= 0x02; // Desliga o LCD16X2 LCDSetPosition(0,1); LCDPrintString("ADC 2 Click Ex."); // Display message on the Lcd LCDSetPosition(1,1); LCDPrintString("Value: "); // Display message on the Lcd do { adcValue = MCP3551_Read(); // Read ADC value from MCP3551 sprintf(strADC_Value,"%ld",adcValue); LCDSetPosition(1,8); LCDPrintString(" "); // Reading Error if (adcValue == -4000000){ LCDSetPosition(1,8); LCDPrintString("Erro"); // Reading Error } else if (adcValue == 3000000) { LCDSetPosition(1,8); LCDPrintString("OVH"); // Overflow High } else if (adcValue == -3000000) { LCDSetPosition(1,8); LCDPrintString("OVL"); // Overflow Low } else { LCDSetPosition(1,8); LCDPrintString(strADC_Value); // Display message on the Lcd } __delay_cycles(1000000); //__bis_SR_register(LPM3_bits + GIE); // Entra em LPM3 (Modo de Baixo Consumo) }while(1); } #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A(void) // When the value of the TimerA=TACCR0, we get out of the low power mode { __bic_SR_register_on_exit(LPM3_bits + GIE); }

Viewing all articles
Browse latest Browse all 62309

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>