Vous êtes sur la page 1sur 8

Ce fil a été verrouillé.

Si vous avez une question connexe, veuillez cliquer sur le bouton " Poser une question connexe " dans le
coin supérieur droit. La question nouvellement créée sera automatiquement liée à cette question.

problèmes msp430 i2c


Réponses: 33 Joe Shoshana

Vues: 5459

Salut,

J'ai écrit le code suivant:

#include <msp430.h> 

/*
* main.c
*/
taille du caractère signé;
char non signé * dataReceive;
unsigned char * dataTransmit;

unsigned char slaveAddr = 0x20;


int main (void) {
WDTCTL = WDTPW | WDTHOLD; // Arrête la minuterie de surveillance
P1SEL | = BIT7 + BIT6; // Fonctions SET SDA + SCL
P1SEL2 | = BIT7 + BIT6; // Fonctions SET SDA + SCL
UCB0CTL1 | = UCSWRST; // réinitialise
UCB0CTL0 | = UCMST + UCMODE_3 + UCSYNC; // I2C SYNC MASTER MODE
UCB0BR0 = 0x08;
UCB0BR1 = 0;
UCB0I2CSA = slaveAddr;
UCB0CTL1 | = UCSSEL_3 + UCSWRST; // SMCLK
UCB0CTL1 & = ~ UCSWRST; // reprise de l'opération
UCB0I2CIE | = UCNACKIE;
IE2 | = UCB0TXIE + UCB0RXIE; // Activer l'interruption TX & RX
dataTransmit = "Bonjour";
taille = 5;

while (UCB0STAT & UCBBUSY); // en attente de l'arrêt principal d'être occupé


UCB0CTL1 | = UCTR + UCTXSTT; // définir l'émetteur et démarrer la condition
__bis_SR_register (GIE);
while (1) {
}
renvoie 0;
}

#pragma vector = USCIAB0RX_VECTOR


__interrupt void USCIAB0RX_ISR (void)
{
if (UCB0STAT & UCNACKIFG) {// send STOP si l'esclave envoie NACK
UCB0CTL1 | = UCTXSTP;
UCB0STAT & = ~ UCNACKIFG;
}

#pragma vector = USCIAB0TX_VECTOR


__interrupt void USCIAB0TX_ISR (void)
{
if (IFG2 & UCB0RXIFG) {
if (size == 0) {
UCB0CTL1 | = UCTXSTP; // Condition d'arrêt I2C
* dataReceive = UCB0RXBUF;
dataReceive ++;
}
else {
* dataReceive = UCB0RXBUF;
dataReceive ++;
Taille--;
}
}
else {
if (taille == 0) {
UCB0CTL1 | = UCTXSTP; // Condition d'arrêt I2C
IFG2 & = ~ UCB0TXIFG; // Effacer l'indicateur int USCI_B0 TX
}
else {
UCB0TXBUF = * dataTransmit;
dataTransmit ++;
Taille--;
}
}
}

Et j'ai ces questions:

1.Quand je suis en train de câbler les lignes:

P1SEL | = BIT7 + BIT6; // Fonctions SET SDA + SCL


P1SEL2 | = BIT7 + BIT6; // Fonctions SET SDA + SCL

le code est bloqué dans cette ligne: while (UCB0STAT & UCBBUSY);
ce qui signifie que le bit UCBBUSY est élevé.

mais quand j'omets une des lignes P1SEL le code ne bloque pas (le bit UCBBUSY est bas)

pourquoi cela se produit-il?


2. après avoir passé la boucle while "busy", il exécute l'événement d'interruption une fois qui ne prend qu'un seul
caractère et ne l'affiche pas sur l'esclave (lcd), je suppose que l'interruption se poursuivra jusqu'à ce qu'il obtienne un
bit d'arrêt (UCTXSTP) et le drapeau est clair (UCB0TXIFG) mais il ne

3. comment calcule la vitesse de communication smclk? j'ai cherché, mais je n'ai rien trouvé.

L'adresse esclave est l'adresse correcte.

Je vous remercie.

MISE À JOUR:

le msp est msp430g2553 

J'attache une image du circuit

bleu - vcc

orange - gnd

jaune -scl

violet - sda

vert - vcc avec résistances 10k pour sda et scl


msp430g2553 #ccs # I2C

Joe Shoshana

33 Réponses

Clemens Ladisch

Quel MSP? Et montrez votre circuit.

Joe Shoshana

En réponse à Clemens Ladisch :

Salut merci pour la réponse


je mets à jour ma question, voir ci-dessus.
Merci de votre aide

Clemens Ladisch
En réponse à Joe Shoshana :

Comment les résistances de pull-up sont-elles connectées?

Joe Shoshana

En réponse à Clemens Ladisch :

ils sont parallèles


je veux dire le même vcc mais en divisant un au scl et l'autre au sda

Clemens Ladisch

En réponse à Joe Shoshana :

Can you measure the SDA/SCL lines with an oscilloscope or logic analyzer? Or at least a multimeter?

Joe Shoshana

In reply to Clemens Ladisch:

Yes, I've checked with multimeter

General Voltage 3.7V

and both sda and scl 3.7V


Clemens Ladisch

In reply to Joe Shoshana:

You should use a supply voltage that is actually allowed.

I don't know why UCBBUSY is set; in theory, this should not be possible directly after the reset.

Joe Shoshana

In reply to Clemens Ladisch:

Hi,
After you said you don't know why UCBBUSY is set, i assumed something wrong with the launchpad so i took another
and suddnely it's not busy anymore and it looks like it's working but, i don't see the characters on the lcd.
what do i need to investigate to see the results?

Clemens Ladisch

In reply to Joe Shoshana:

This sounds as if the SCL pin of the old LaunchPad is broken. Probably overvoltage (the nominal upper limit is 3.3 V) or
ESD.

I doubt that you can simply send characters over I²C. Is there any documentation about the I²C protocol?

Joe Shoshana
In reply to Clemens Ladisch:

yes, i have documentation for i2c protocol on the following link: www.nxp.com/.../PCF8574.pdf
the PCF8574 is the chip for the lcd's i2c controller(YWrobot)
another thing i notice, the SCL line controls the rythm of the data transfer, so the voltage on it is changing (high to low,
low to high) but i see that is always hi, i mean getting 3.7V everytime. i assume it needs to be ~2.5V (making an average)
does it make any sense?

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.

Vous aimerez peut-être aussi