MSP430, Microcontrollori 16 bit Ultra Low Power

PCF8574A controllato da MSP430

  • borelg
  • Autore della discussione
  • Elit Utente
  • Elit Utente
Di più
12 Anni 11 Mesi fa #1 da borelg
PCF8574A controllato da MSP430 è stato creato da borelg
Quello che dovrei fare con l'I2C è controllare un PCF8574AP per espandere gli ingressi (altri 6 ingressi)
Sto provando a fare qualcosa di più semplice, ma non riesco neanche a ricevere l'ACK dopo aver inviato lo Start Condition:
Code:
WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1 = CALBC1_16MHZ; // Set DCO to calibrated 16 MHz. DCOCTL = CALDCO_16MHZ; BCSCTL2 = 0; P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0 P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0 UCB0CTL1 |= UCSWRST; // Enable SW reset UCB0CTL0 = UCMST+UCMODE_3+UCSYNC; // I2C Master, synchronous mode UCB0CTL1 = UCSSEL_2+UCSWRST; // Use SMCLK, keep SW reset UCB0BR0 = 160; // fSCL = SMCLK/160 = ~100kHz UCB0BR1 = 0; UCB0I2CSA = KEYB_ADDRESS; // Set slave address UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation IE2 |= UCB0RXIE; // Enable RX interrupt UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition while (UCB0CTL1 & UCTXSTT); // Loop until I2C STT is sent UCB0TXBUF = 0xFF; UCB0CTL1 |= UCTXSTP; // I2C stop condition after 1st TX

Mi si blocca nel while e non si smuove.
L'indirizzo è 0x38 perchè ho messo a massa A2 A1 A0 ed è un PCF8574A.
Qualche idea?
Grazie :)

Si prega Accesso o Crea un account a partecipare alla conversazione.

  • Mauro Laurenti
  • Moderatore
  • Moderatore
Di più
12 Anni 11 Mesi fa #2 da Mauro Laurenti
Risposta da Mauro Laurenti al topic Re: PCF8574A controllato da MSP430
Ciao,

non ho visto i singoli bit ma ti dico che tra gli esempi di Code Composer Studio per MSP430G2xx3 c'e' proppio un programma essenziale per PCF8574. Leggge 4 bit in ingresso e li rispedisce in uscita agli altri 4 bit.

Usa quello come esempio. Il programma e' compilabile sia per CCS che IAR quindi lo puoi riciclare completamente.
Per accedere all'esempio scarica l'ultima versione di CCS 5.2.
Vai al menu Help-> Welcome to CCS
Poi seleziona MSP430Ware nel Packages nella finestra che si apre.

Vai a device, seleziona MSP430G -> Code Examples -> MSP430G2x53

Saluti,

Mauro

Si prega Accesso o Crea un account a partecipare alla conversazione.

  • borelg
  • Autore della discussione
  • Elit Utente
  • Elit Utente
Di più
12 Anni 11 Mesi fa #3 da borelg
Risposta da borelg al topic Re: PCF8574A controllato da MSP430
Ciao Mauro, il mio programma si basa proprio su quell'esempio l'unica diferenza nelle configurazioni è la ferquenza di clock che io ho impostato a 16 MHz. Per scrupolo comunque ho provato anche quell'esempio, ma il risultato è lo stesso.
In realtà comunque non ho capito molto bene il funzionamento di quel programma. In teoria per usare come ingressi tutti i pin del pcf8574 la procedura di ricezione non è questa?
-Invio start condition come tx
-Invio start condition come rx
-Il pcf8574 mi spedisce i valori degli ingressi
-Invio stop condition.

Nell'esempio invece spediscono direttamente lo start come rx (per ricevere i primi 4 ingressi) e poi lo start come tx per spedire i 4 ingressi ricevuti e visualizzarli come uscite.

Qualche idea? :)
Grazie.

Per comodità metto anche il codice dell'esempio:
Code:
#include "msp430g2553.h" void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop Watchdog Timer P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0 P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0 UCB0CTL1 |= UCSWRST; // Enable SW reset UCB0CTL0 = UCMST+UCMODE_3+UCSYNC; // I2C Master, synchronous mode UCB0CTL1 = UCSSEL_2+UCSWRST; // Use SMCLK, keep SW reset UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz UCB0BR1 = 0; UCB0I2CSA = 0x20; // Set slave address UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation IE2 |= UCB0RXIE; // Enable RX interrupt TACCTL0 = CCIE; // TACCR0 interrupt enabled TACTL = TASSEL_2 + MC_2; // SMCLK, contmode while (1) { __bis_SR_register(CPUOFF + GIE); // CPU off, interrupts enabled UCB0CTL1 &= ~UCTR; // I2C RX UCB0CTL1 |= UCTXSTT; // I2C start condition while (UCB0CTL1 & UCTXSTT); // Loop until I2C STT is sent UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition __bis_SR_register(CPUOFF + GIE); // CPU off, interrupts enabled while (UCB0CTL1 & UCTXSTT); // Loop until I2C STT is sent UCB0CTL1 |= UCTXSTP; // I2C stop condition after 1st TX } } #pragma vector = TIMER0_A0_VECTOR __interrupt void TA0_ISR(void) { __bic_SR_register_on_exit(CPUOFF); // Exit LPM0 } // USCI_B0 Data ISR #pragma vector = USCIAB0TX_VECTOR __interrupt void USCIAB0TX_ISR(void) { UCB0TXBUF = (UCB0RXBUF << 4) | 0x0f; // Move RX data to TX __bic_SR_register_on_exit(CPUOFF); // Exit LPM0 }

Si prega Accesso o Crea un account a partecipare alla conversazione.

  • Mauro Laurenti
  • Moderatore
  • Moderatore
Di più
12 Anni 11 Mesi fa #4 da Mauro Laurenti
Risposta da Mauro Laurenti al topic Re: PCF8574A controllato da MSP430
Ciao,

vorrei in primo luogo considerare la libreria esatta.

hai costruito l'hardware su millefori?

Potresti testare con PIC18 e la libreria per C18 che il tuo hardware funziona correttamente?
Attento alle due versioni di PCF8574A e non A.

Una volta che funziona con la libreria C18, sappiamo che l'hardware e' coretto.

Purtroppo fare un debug con nuovo hardware e software e' sempre complicato.

Se apri la libreria che ho scritto vedi anche la sequenza corretta per comunicare in lettura e scrittura con il PCF8574.

Saluti,

Mauro

Si prega Accesso o Crea un account a partecipare alla conversazione.

  • borelg
  • Autore della discussione
  • Elit Utente
  • Elit Utente
Di più
12 Anni 11 Mesi fa #5 da borelg
Risposta da borelg al topic Re: PCF8574A controllato da MSP430
Per un po' non mi potrò alzare da letto quindi l'hardware non posso provarlo... mi sono rotto una gamba :(
Comunque può darsi che l'errore sia nella procedura di comunicazione. Infatti nel datasheet c'è scritto:

I2C communication with this device is initiated by a master sending a start condition, a high-to-low transition on
the SDA I/O while the SCL input is high. After the start condition, the device address byte is sent,
most-significant bit (MSB) first, including the data direction bit (R/W). This device does not respond to the general
call address. After receiving the valid address byte, this device responds with an acknowledge, a low on the SDA
I/O during the high of the acknowledge-related clock pulse. The address inputs (A0–A2) of the slave device must
not be changed between the start and the stop conditions.
The data byte follows the address acknowledge. If the R/W bit is high, the data from this device are the values
read from the P port. If the R/W bit is low, the data are from the master, to be output to the P port. The data byte
is followed by an acknowledge sent from this device. If other data bytes are sent from the master, following the
acknowledge, they are ignored by this device. Data are output only if complete bytes are received and
acknowledged. The output data will be valid at time, tpv, after the low-to-high transition of SCL and during the
clock cycle for the acknowledge.
A stop condition, a low-to-high transition on the SDA I/O while the SCL input is high, is sent by the master.

Cioè basta mandare lo start condition, l'indirizzo con il bit R/W appropriato e se sono in write spedire le uscite, altrimenti aspettare che lui mi spedisca gli ingressi.
MI sbaglio?
Il fatto di utilizzare le porte come ingressi implica che prima io debba impostarli a livello logico "1" vero? A me sembrava che questa inizializzazione avvenisse di default all'accensione del componente, avevo capito male?
Grazie :)

Si prega Accesso o Crea un account a partecipare alla conversazione.

Moderatori: Mauro LaurentiMatteo Garia

Registrati al sito

Accedi a tutte le risorse e articoli non visibili pubblicamente, puoi registrarti con pochi passi.

Registrati al sito LaurTec.

Forum - Ultimi messaggi