es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Comunicación en paralelo (no en cascada) de 74hc595 a través de líneas de bus comunes.

Estoy intentando enviar datos en paralelo (no en cascada) desde CD4094B a un 74hc595 a través de líneas de bus comunes. Estoy enviando 16 bits para colocar los primeros 8 bits en el 74hc595(1) y los segundos 8 bits en el 74hc595(2). Pero obtengo los mismos 8 bits (10101010) en ambos dispositivos 74hc595.

¿Cómo enviar los 16 bits de manera que los primeros 8 bits se coloquen en el primer 74hc595 y los segundos 8 bits se coloquen en el segundo 74hc595?

Código:

uint8_t test[16] = {1,1,1,1,0,0,0,0,1,0,1,0,1,0,1,0};

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_11, GPIO_PIN_SET); // CD4094 OE

for (int bit=0; bit<16; bit++)
{

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET);  //CD4094 STROBE

output = test[bit] & 1;

if (output) {

   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_SET); //CD4094 DATA

} else {

   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_RESET); //CD4094 DATA 

}

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET); //CD4094 CLOCK

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);  

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_SET); // CD4094 STROBE

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); // 74hc595 CLOCK

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);  

}

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET); // 74hc595 OE

HAL_Delay(3000);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);

HAL_Delay(3000);

Esquemático de la PCB:

PCB Schematic

Tags:  , ,

Answer

  1. Avatar for davy.ai

    Parece que el código solo está enviando datos a un registro de desplazamiento, por lo que ambos dispositivos 74hc595 están recibiendo los mismos 8 bits. Para enviar los primeros 8 bits al primer 74hc595 y los segundos 8 bits al segundo 74hc595, necesitas modificar el código para enviar los datos a cada registro de desplazamiento por separado.

    Un enfoque sería configurar dos pines GPIO separados para la señal STROBE, uno para cada registro de desplazamiento. Necesitarías modificar el código para alternar entre los dos pines cada vez que envía un bit. Por ejemplo, podrías usar el pin PB10 para el primer registro de desplazamiento y PB9 para el segundo registro de desplazamiento:

    uint8_t test[16] = {1,1,1,1,0,0,0,0,1,0,1,0,1,0,1,0};
    
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_11, GPIO_PIN_SET); // CD4094 OE
    
    for (int bit=0; bit<16; bit++)
    {
    
       if (bit<8) {
           HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET);  //CD4094 STROBE 1
       } else {
           HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET);  //CD4094 STROBE 2
       }
    
       output = test[bit] & 1;
    
       if (output) {
    
           HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_SET); //CD4094 DATA
    
       } else {
    
           HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_RESET); //CD4094 DATA 
       }
    
       HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET); //CD4094 CLOCK
    
       HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);  
    
       if (bit<8) {
           HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_SET); // CD4094 STROBE 1
       } else {
           HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_SET); // CD4094 STROBE 2
       }
    
       HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); // 74hc595 CLOCK 1
    
       HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);  
    
       if (bit>=8) {
           HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); // 74hc595 CLOCK 2
           HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);  
       }
    }
    
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET); // 74hc595 OE
    
    HAL_Delay(3000);
    
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);
    
    HAL_Delay(3000);
    
    

    Ten en cuenta que este código de ejemplo asume que has conectado la señal STROBE 1 a PB10 y la señal STROBE 2 a PB9. Además, asume que has conectado la señal CLOCK 1 a PB12 y la señal CLOCK 2 a otro pin GPIO (no mostrado en el esquema). Deberás ajustar el código y las conexiones para que coincidan con tu configuración específica.

Comments are closed.