Forum: Mikrocontroller und Digitale Elektronik Implementierung eines ADT7301 an einem MSP430FR5729


von Dennis (Gast)



Lesenswert?

Hallo,

ich versuche einen ADT7301 Temperatursensor an einem MSP430FR5729 zu 
implementieren.

Jedoch weiß ich nicht wie ich den Sensor auf dem MSP430 Microcontroller 
ansteuere bzw wie ich es implementieren soll.

Die Verkabelung sieht wie folgt aus:
1
                         MSP430FR5729
2
                       ----------------
3
                      |                |
4
 Data Out (UCA1SIMO) -|P2.5        P2.6|- Data In (UCA1SOMI)
5
                      |                |
6
    Slave reset (CS) -|P2.3        P2.4|- Serial Clock Out (UCA1CLK)
7
                      |                |
8
                       ----------------

Der unten stehende C Code zeigt meine MSP430 Initalisierung.
1
#include <msp430.h>
2
#include "base.h"
3
4
void SPI_init(void); // initialize the SPI communication
5
void SPI_send(unsigned int data);
6
void CS_Init(void); // clock system
7
8
int main(void)
9
{
10
    WDTCTL = WDTPW + WDTHOLD; // stop Watchdog timer
11
12
    CS_Init(); // set Timing
13
14
    SPI_init(); // Initialize SPI-Module UCA1
15
16
    while (1)
17
    {
18
        //_low_power_mode_3 (); // do nothing
19
    }
20
}
21
22
23
void SPI_init(void)
24
{
25
    SETBIT(P2SEL1, BIT4); // Select secondary function of P2.4 (UCA1CLK)
26
    SETBIT(P2SEL1, BIT5); // Select secondary function of P2.5 (UCA1SIMO)
27
    SETBIT(P2SEL1, BIT6); // Select secondary function of P2.6 (UCA1SOMI)
28
29
    SETBIT(P2DIR, BIT3); // Declare P2.3 as Select Slave port
30
    SETBIT(P2OUT, BIT3); // Start with high on Select Slave P2.3
31
32
    SETBIT(UCA1CTLW0, UCSWRST); // Software reset enable. Have to be selected here
33
    SETBIT(UCA1CTLW0, UCCKPH); // select clock phase to rising clock phase
34
    SETBIT(UCA1CTLW0, UCMSB); // direction of shift register
35
    SETBIT(UCA1CTLW0, UCMST); // SPI master
36
    SETBIT(UCA1CTLW0, UCSYNC); // Synchronous mode enable
37
    SETBIT(UCA1CTLW0, UCSSEL_2); // SMCLK clock selected
38
}
39
40
void SPI_send(unsigned int data)
41
{
42
    UCA1TXBUF = data; // send data
43
}
44
45
void CS_Init(void) //clock system
46
{
47
    // set up Clock System
48
    CSCTL0 = CSKEY; // enable clock system
49
    CSCTL1 = DCOFSEL_3; // frequency = 8,0 MHz
50
    CSCTL2 = SELA__XT1CLK | SELS__DCOCLK | SELM__DCOCLK; // select clock sources
51
    CSCTL3 = DIVA__8 | DIVS__32 | DIVM__8; // set frequency divider
52
    CSCTL4 = XT2OFF | XTS | XT1DRIVE_0; // XT2 disabled, XT1: HF mode, low power, no bypass
53
    CSCTL0_H = 0; // disable clock system
54
}

Beitrag #5689025 wurde von einem Moderator gelöscht.
von Clemens L. (c_l)


Lesenswert?

Dennis schrieb:
> SETBIT(UCA1CTLW0, UCSWRST);

Solange das SPI-Modul im Reset ist, läuft es nicht.
Siehe z.B. MSP430FR57xx_uscia0_spi_09.c, wie man's richtig macht.

> CSCTL2 = SELA__XT1CLK | SELS__DCOCLK | SELM__DCOCLK;
> CSCTL4 = XT2OFF | XTS | XT1DRIVE_0;

Das genügt nicht, um den Quarz zum Laufen zu bringen. Siehe das selbe 
Beispielprogramm.

>     UCA1TXBUF = data;

Das funktioniert nur, wenn TXBUF gerade leer ist. Du musst vorher 
warten, bis TXIFG gesetzt ist.

: Bearbeitet durch User
von Dennis (Gast)


Lesenswert?

Danke Clemens L.
Das macht alles allerdings Sinn.

Habe das Example von MSP430 auch schon mal implementiert, aber da hatte 
ich bestimmt auch einen Fehler gehabt.
Werde es nochmal probieren :)

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.