This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430G2553 ADC10 DTC 写入Flash的问题

Other Parts Discussed in Thread: MSP430G2553

不好意思,想问一下DTC直接写Flash的问题,按照手册上的说法,DTC可以直接写Anywhere?但是我往0xe800的Flash的位置写值,却读不出来。PS:0xe800这个地址值是查.map文件找到的。我把0xe800的地址改成0x200(ram的地址,也是示例中DTC写入的位置),程序又能正常运行。我的测试方法是,往A4(P1.4)接入一个0.5V的直流电压,当地址为0x200时得到temp变量的值为217左右,符合实际,当地址用0xe800时得到temp的最终值为65536(flash全为1,没有写入内容?)。我想知道这个怎么回事,谢谢~ ^_^

我的程序代码如下:

#include <msp430G2553.h>

/*
* main.c
*/
#define uint unsigned int
#define u8 unsigned char

int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// VREF-VSS 4x MSC REF 2.5V ON IE
ADC10CTL0 = SREF_1 + ADC10SHT_0 + MSC + REFON + REF2_5V + ADC10ON + ADC10IE;
// Repeat-S A4 ADC10OSC ADC10DIV_0
ADC10CTL1 = CONSEQ_2 + INCH_4 + ADC10SSEL_0 ;
ADC10AE0 = 0x10;//A4
//

ADC10DTC0 = ADC10TB;

//128 points *2?
ADC10DTC1 = 0x80;

P1DIR |= 0x01; // Set P1.0 to output direction

ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active
ADC10SA = 0xe800; // Data buffer start
P1OUT |= 0x01; // Set P1.0 LED on
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
P1OUT &= ~0x01; // Clear P1.0 LED off

volatile unsigned int i,temp;
for(i=0;i!=128;++i)
{
temp = *(u8 *)(0xe800+2*i);
temp = temp << 8;
temp |= *(u8 *)(0xe800+2*i+1);
}

return 0;
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}

  • 向Flash中写入数据需要配置相应的寄存器


      FCTL2 = FWKEY + FSSEL0 + FN0;             // MCLK/2 for Flash Timing Generator
      value = 0;                                // Initialize value

    void write_SegA (char value)
    {
      char *Flash_ptr;                          // Flash pointer
      unsigned int i;

      Flash_ptr = (char *) 0x1080;              // Initialize Flash pointer
      FCTL1 = FWKEY + ERASE;                    // Set Erase bit
      FCTL3 = FWKEY;                            // Clear Lock bit
      *Flash_ptr = 0;                           // Dummy write to erase Flash segment

      FCTL1 = FWKEY + WRT;                      // Set WRT bit for write operation

      for (i=0; i<128; i++)
      {
        *Flash_ptr++ = value;                   // Write value to flash
      }

      FCTL1 = FWKEY;                            // Clear WRT bit
      FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
    }

  • 嗯,谢谢回复,但是DTC都在内部自己跑,我用DTC写Flash时应该怎么设置呢?

    我把中间那段代码修改了一下:

    ADC10CTL0 &= ~ENC;
    while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active
    ADC10SA = 0xe800; // Data buffer start
    P1OUT |= 0x01; // Set P1.0 LED on

    FCTL1 = FWKEY + WRT;                // Write bit = 1  

    ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit

    FCTL3 = FWKEY + LOCK;               // Lock = 1

    P1OUT &= ~0x01; // Clear P1.0 LED off

    增加了在ENC前的一个WRT和后的一个LOCK。这样出来的值只有第一个是对的。

    这样岂不是说,用DTC往Flash里写每一个值我都需要先手动置WRT?

    但是DTC又在内部自己跑,我应该怎么操作呢?谢谢

  • 你可以先把DTC的数据先入到RAM的数组中,然后把数组的数据写入到Flash中~

  • 。。。。好吧T^T,主要是数组有点大,本来需要采256个点,直接写RAM的话,RAM就要溢出了的感觉

    看到DTC能直接写Flash正感觉开心呢。。

  • 对了。还想问一个问题^_^ ,ADC10的采样率有什么办法可以确定吗? 是不是只能通过 t sample 和 t convert 和ADC10CLK进行估算?

  • 是的,但是注意一点在ADC采集的信号阻抗很大时注意Tsample的时间,此时需要增大采样保持的时间才能保证ADC的转换精度,具体的时间计算可以参考用户手册,再就是注意ADC最大200ksps是转换速率~