大家好、我使用的是 msp432P401R。 我想建立 UART 通信。 为了检查传入和传出的数据流,我在 python 中开发了一个 GUI 来打开一个连接到 MSP 的 LED。 我编写了 MSP 代码和 Python 代码、但显然在 CCS 文本编辑器(对于 MSP)和 VScode (对于 python)中没有报告任何错误。 但是、当我运行代码时、什么都不起作用。
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.
大家好、我使用的是 msp432P401R。 我想建立 UART 通信。 为了检查传入和传出的数据流,我在 python 中开发了一个 GUI 来打开一个连接到 MSP 的 LED。 我编写了 MSP 代码和 Python 代码、但显然在 CCS 文本编辑器(对于 MSP)和 VScode (对于 python)中没有报告任何错误。 但是、当我运行代码时、什么都不起作用。
#include <stdio.h>
#include <stdint.h>
#include "msp432.h"
#define PCMKEY_value 0x695A0000 //mot de passe pour le registre PCMCTL0
#define CS_KEY_value 0x0000695A //mot de passe pour le registre CS
uint8_t rx_value;
void Led_Confug(void){
P2->DIR |= 0x02; // Configuration du port P4.0, P4.1, P4.2 et P4.3 comme sortie
}
void Led_Off(void){
P2->OUT &= ~0x02;
}
void Led_On(void){
P2->OUT |= 0x02;
}
void DCO_clock()
{
CS->KEY = CS_KEY_value;
CS->CTL0 = CS_CTL0_DCORSEL_1;//3MHz
CS->CTL1 = CS_CTL1_SELA_3 + CS_CTL1_SELM_3 + CS_CTL1_SELS_3; //choix de Aclk=REFOCLK, MCLK=DCOCLK, SMCLK et HSMCLK =DCOCLK
CS->KEY = 0;
}
void UARTA0_conf(void){
// Activation du bit CTLW0 pour la configuration des différents registres
EUSCI_A0->CTLW0 = 0x0001;
// PIN configuration
P2->SEL0 |= 0x0C;
P2->SEL1 &= ~0x0C;
/* 1 stop bit, no parity, SMCLK, 8-bit data */
UCB0CTLW0 = 0x081;
//Choix de la vitesse pour le baudrate
//On choisi une vitesse de 9600
EUSCI_A0->BRW = 26;
// Désactivation du mode reset
EUSCI_A0->CTLW0 &= ~0x01;
}
void UARTA0_reception(void){
// On vérifie si la transmission est ok
if(EUSCI_A0->IFG & 0x0001){
EUSCI_A0->IFG &= ~0x0001; // clear flag
rx_value = EUSCI_A0->RXBUF; // copie de la donnée
}
}
void UARTA0_caractere(char c) {
while(!(EUSCI_A0->IFG & 0x02)) // On regarde si le tampon est vide
EUSCI_A0->TXBUF = c; // Envoie du caractère
}
void UARTA0_transmission(char* s) {
while (*s != 0) // On vérifie si ce n'est pas une fin de chaine de caractère
UARTA0_caractere(*s++); // On collecte les caractères
}
void main(void){
DCO_clock();
UARTA0_conf();
Led_Confug();
UARTA0_reception();
if (rx_value==a){
Led_On();
}
if (rx_value==b){
Led_Off();
}
}
#include <stdio.h>
#include <stdint.h>
#include "msp432.h"
#define CS_KEY_value 0x0000695A //Unlock CS module for register access
void DCO_clock()
{
CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
CS->CTL0 = 0; // Reset tuning parameters
CS->CTL0 = CS_CTL0_DCORSEL_3; // Set DCO to 12MHz (nominal, center of 8-16MHz range)
CS->CTL1 = CS_CTL1_SELA_2 | // Select ACLK = REFO
CS_CTL1_SELS_3 | // SMCLK = DCO
CS_CTL1_SELM_3; // MCLK = DCO
CS->KEY = 0; // Lock CS module from unintended accesses
}
void UARTAO_conf(){
// Configure UART
EUSCI_A0->CTLW0 |= EUSCI_A_CTLW0_SWRST; // Put eUSCI in reset
EUSCI_A0->CTLW0 = EUSCI_A_CTLW0_SWRST | // Remain eUSCI in reset
EUSCI_A_CTLW0_SSEL__SMCLK | EUSCI_A_CTLW0_MODE_3; // Configure eUSCI clock source for SMCLK
//UCA0CTLW0 = UCMODE_3 + UCSYNC + UCSSEL_3 + UCSWRST; //communication de type I2C en mode maitre + synchro, SMCLK, et reset mainten
// Baud Rate calculation
// 12000000/(16*9600) = 78.125
// Fractional portion = 0.125
// User's Guide Table 21-4: UCBRSx = 0x10
// UCBRFx = int ( (78.125-78)*16) = 2
EUSCI_A0->BRW = 78; // 12000000/16/9600
EUSCI_A0->MCTLW = (2 << EUSCI_A_MCTLW_BRF_OFS) |
EUSCI_A_MCTLW_OS16;
EUSCI_A0->CTLW0 &= ~EUSCI_A_CTLW0_SWRST; // Initialize eUSCI
}
void send_data(char *str)
{
int i; // create variable
// iterate over the end of the string
for (i = 0; str[i] != '\0'; i++)
{
while (!(EUSCI_A0->IFG & EUSCI_A_IFG_TXIFG)); // wait until is ready to transmit
EUSCI_A0->TXBUF = str[i]; // send character through buffer
}
}
void main(void){
DCO_clock();
UARTAO_conf();
while(1){
send_data("AB");
}
}