MSP430G2553 从 MCP3464 ADC 转换器 (SPI) 接收错误值

问题描述 投票:0回答:1

我已将 MCP3464 焊接在 PCB 断板上,并将其与 MSP430G2553 连接。 然后我编写了一个测试代码,看看是否可以对 MCP3464 的内部寄存器进行读写。但是当我尝试从中读取时,我每次都会得到错误的值。

这是我尝试过的:

  • 将新的 MCP3464 焊接到新的断线板上
  • 尝试找到 MCP430G2553 的示例代码

数据表 ADC 转换器 MCP3464

微控制器 MSP430G2553 数据表

家庭用户指南 MSP430G2553

在此示例代码中,我尝试写入定时器寄存器,然后从中读取以查看是否输出相同的值,这里我发送 0xA56547,但收到 0xF7E7C0。

这是代码:

#include <msp430.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>

#include "MCP3464_Commands.h"           // library with command's for the MCP3464

uint8_t rcv;


void init_Clock(void);
void SPI_Send(uint8_t data);
void configSPI_A(void);


void main(void)
{
    P1DIR |= BIT3;          // BIT 3 is CS
    P1OUT |= BIT3;          // CS is HIGH

    init_Clock();           // clock configuration
    configSPI_A();          // SPI A configuration


while (1)
{



    P1OUT |= BIT3;                          // CS is HIGH
    P1OUT &= ~BIT3;                         // CS is LOW
    SPI_Send(0b111000);            // Here the MSP430 sends a full reset to the MCP3464

    P1OUT |= BIT3;                          // CS is HIGH


    P1OUT &= ~BIT3;                         // CS is LOW
    SPI_Send(0b10 + 0b100000);    // Here i want to write data to the TIMER register, this is a 24 bit register

    SPI_Send(0b10100101);                   // This is the 24 bit data that i send to the MCP3464
    SPI_Send(0b01100101);
    SPI_Send(0b01000111);

    P1OUT |= BIT3;                          //CS is HIGH



    P1OUT &= ~BIT3;                         // CS is LOW

    SPI_Send(0b11 + 0b100000);     // here i want to read form the time register

    SPI_Send(0);                            // since this is a 24 bit register i send nothing and just
    SPI_Send(0);                            // read form the UCA0RXBUF what the data is in debug mode
    SPI_Send(0);

    P1OUT |= BIT3;                          // CS is HIGH

    }
}


void SPI_Send(uint8_t data)
{

    UCA0TXBUF = data;                           // data to UCA0TXBUF register
    while(UCA0STAT & UCBUSY);                   // wait until the data has bean send

    rcv = UCA0RXBUF;                            // Received data from the UCA0RXBUF to rcv

}

void configSPI_A(void)
{
    P1SEL = BIT1 + BIT2 + BIT4;             // PIN 1 2 and 4 for spi protocol
    P1SEL2 = BIT1 + BIT2 + BIT4;            // PIN 1 2 and 4 for spi protocol 2


    UCA0CTL1 |= UCSWRST;                                           //enable, usci logic held in reset state
    UCA0CTL0 |= UCMSB + UCMST + UCSYNC + UCCKPH + UCCKPL;          // SPI Mode [1.1], most significant bit first, Syncronish, master mode,
    UCA0CTL1 |= UCSSEL_2 ;                                         // select SMCLK


    UCA0BR0 = 20;                             // the clock divider is set to 20 so that the spi clock can be 800 KHz
    UCA0BR1 = 0;

    UCA0CTL1 &= ~UCSWRST;
}


// set clock to max
void init_Clock(void)
{

    WDTCTL = WDTPW + WDTHOLD;   // hold watchdog
    BCSCTL2 = SELM_0 + DIVM_0 + DIVS_0;

    if (CALBC1_16MHZ != 0xFF)
    {
        __delay_cycles(100000);
        DCOCTL = 0x00;
        BCSCTL1 = CALBC1_16MHZ;
        DCOCTL = CALDCO_16MHZ;
    }

}

更新

这是我从示波器上截取的一些屏幕截图

  • 蓝色是CS
  • 黄色是时钟
  • 绿色是味噌
  • 紫色是MOSI

Full image of SPI comunication

Zomed in image 1

Zomed in image 2

Zomed in image 3

c spi microchip msp430 adc
1个回答
0
投票

嗨,我已经用 esp32 运行了 mcp3464。我需要 10 Ksps 的高采样率,但是 我只是在 10 sps 下测试 adc 不起作用。为什么???

© www.soinside.com 2019 - 2024. All rights reserved.