Skip to main content
added 2291 characters in body
Source Link

One of my codeshere is just a lazy test. Not even this works, test nor shutdown. simple test code:

#include <avr/io.h>/test

#include <util<avr/delayio.h>
 

int main(void)
{
    


DDRB = 0b00000111; // pin 1(data), 2(clock) and 3(latch) are outputs
/*
//display test
PORTB = 0b00000000;1 << PINB0; // data pin 1 is high
PORTB = 0 << PINB1; // clock pin 2 is low
PORTB = 0 << PINB2; // latch pin 3 is low

_delay_ms(PORTB = 1); << PINB1; // clock pin is high
uint16_tPORTB data;= 0 << PINB1; // clock pin is low
data
PORTB = 0b0000110000000000;1 << PINB1; // dataclock topin shiftis outhigh
PORTB to= the0 register<< PINB1; // clock pin is low

PORTB = 1 << PINB1; //read bitclock pin is high
uint16_tPORTB mask;= 0 << PINB1; // clock pin is low
for
PORTB (mask= 1 << PINB1; // clock pin is high
PORTB = 0b1000000000000000;0 mask>0;<< maskPINB1; >>=// 1)clock pin is low
{
PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; //iterate throughclock bitpin maskis low

PORTB = 1 << ifPINB1; (data// &clock mask)pin is high
PORTB = 0 << {PINB1; // ifclock bitwisepin ANDis resolveslow

PORTB to= true1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // sendclock onepin is high
PORTB = 0 << PINB1; // clock pin is low

// next 8 bits

PORTB |== 1 << PINB0;PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin _delay_ms(is low

PORTB = 1); << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // tickclock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB |== 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin _delay_ms(is low

PORTB = 1); << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // tockclock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB &== ~(1 << PINB1);PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin _delay_ms(is low

PORTB = 1); << PINB2; // latch pin 3 is high

*/

// shutdown
PORTB = 1 }<< PINB0; // data pin 1 is high
PORTB = 0 << else{PINB1; //if bitwiseclock andpin resolves2 tois falselow
PORTB = 0 << PINB2; // latch pin 3 is low

PORTB = 1 << PINB1; // sendclock 0pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB &== ~(1 << PINB0);PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin _delay_ms(is low

PORTB = 1); << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // tickclock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB |== 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is _delay_ms(low

PORTB = 1); << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB0; // tockdata pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB &== ~(0 << PINB1; // clock pin is low

PORTB = 1 << PINB1);PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

// _delay_ms(next 8 bits

PORTB = 1); << PINB1; // clock pin is high
PORTB = 0 << }PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
}PORTB = 0 << PINB1; // clock pin is low

PORTB |== 1 << PINB2;PINB1; // latchclock allpin theis datahigh
_delay_ms(PORTB = 0 << PINB1; // clock pin is low

PORTB = 1); << PINB1; // clock pin is high
PORTB &== ~(0 << PINB1; // clock pin is low

PORTB = 1 << PINB2);PINB1; // latchclock pin 3is high
PORTB = 0 << PINB1; // clock pin is low
_delay_ms(1000);
PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low
}
PORTB = 1 << PINB2; // latch pin 3 is high

}

One of my codes:

#include <avr/io.h>
#include <util/delay.h>
 

int main(void)
{
    


DDRB = 0b00000111; // pin 1(data), 2(clock) and 3(latch) are outputs

PORTB = 0b00000000;


_delay_ms(1);
uint16_t data;
data = 0b0000110000000000; // data to shift out to the register
//read bit
uint16_t mask;
for (mask = 0b1000000000000000; mask>0; mask >>= 1)
{
    
    //iterate through bit mask
    if (data & mask)
    { // if bitwise AND resolves to true
        // send one
        PORTB |= 1 << PINB0;
        _delay_ms(1);
        // tick
        PORTB |= 1 << PINB1;
        _delay_ms(1);
        // tock
        PORTB &= ~(1 << PINB1);
        _delay_ms(1);
    }
    else{ //if bitwise and resolves to false
        // send 0
        PORTB &= ~(1 << PINB0);
        _delay_ms(1);
        // tick
        PORTB |= 1 << PINB1;
        _delay_ms(1);
        // tock
        PORTB &= ~(1 << PINB1);
        _delay_ms(1);
    }
    
    
    
}

PORTB |= 1 << PINB2; // latch all the data
_delay_ms(1);
PORTB &= ~(1 << PINB2); // latch pin 3 is low
_delay_ms(1000);


}

here is just a lazy test. Not even this works, test nor shutdown. simple test code:

//test

#include <avr/io.h>

int main(void)
{
DDRB = 0b00000111; // pin 1, 2 and 3 are outputs
/*
//display test
PORTB = 1 << PINB0; // data pin 1 is high
PORTB = 0 << PINB1; // clock pin 2 is low
PORTB = 0 << PINB2; // latch pin 3 is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

// next 8 bits

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB2; // latch pin 3 is high

*/

// shutdown
PORTB = 1 << PINB0; // data pin 1 is high
PORTB = 0 << PINB1; // clock pin 2 is low
PORTB = 0 << PINB2; // latch pin 3 is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB0; // data pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

// next 8 bits

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB1; // clock pin is high
PORTB = 0 << PINB1; // clock pin is low

PORTB = 1 << PINB2; // latch pin 3 is high

}

removed the "//" comment lines in front of delays
Source Link

I'm trying to use an ATmega32 to communicate to a MAX7219 chip for multiplexing with an led matrix. However, I do have multiple different devices that I want to communicate with.

I am trying to communicate with the device without actually using the SPI pins provided on the microcontroller. I have made a test project, but nothing is working. At first it seemed there was something wrong with my code. I've been on other forums and people have shown me better code for doing the job, but still I can't seem to get this working. I've checked all my wiring and even connected it to an Arduino and it ran perfectly. So now I'm thinking it has something to do the the ATmega. Do any pins need pull-up or pull-down resistors on them? Or is there maybe something else that is the issue?

enter image description here

One of my codes:

#include <avr/io.h>
#include <util/delay.h>


int main(void)
{
    


DDRB = 0b00000111; // pin 1(data), 2(clock) and 3(latch) are outputs

PORTB = 0b00000000;


//_delay_ms(1);
uint16_t data;
data = 0b0000110000000000; // data to shift out to the register
//read bit
uint16_t mask;
for (mask = 0b1000000000000000; mask>0; mask >>= 1)
{
    
    //iterate through bit mask
    if (data & mask)
    { // if bitwise AND resolves to true
        // send one
        PORTB |= 1 << PINB0;
        //_delay_ms(1);
        // tick
        PORTB |= 1 << PINB1;
        //_delay_ms(1);
        // tock
        PORTB &= ~(1 << PINB1);
        //_delay_ms(1);
    }
    else{ //if bitwise and resolves to false
        // send 0
        PORTB &= ~(1 << PINB0);
        //_delay_ms(1);
        // tick
        PORTB |= 1 << PINB1;
        //_delay_ms(1);
        // tock
        PORTB &= ~(1 << PINB1);
        //_delay_ms(1);
    }
    
    
    
}

PORTB |= 1 << PINB2; // latch all the data
//_delay_ms(1);
PORTB &= ~(1 << PINB2); // latch pin 3 is low
_delay_ms(1000);


}

I'm trying to use an ATmega32 to communicate to a MAX7219 chip for multiplexing with an led matrix. However, I do have multiple different devices that I want to communicate with.

I am trying to communicate with the device without actually using the SPI pins provided on the microcontroller. I have made a test project, but nothing is working. At first it seemed there was something wrong with my code. I've been on other forums and people have shown me better code for doing the job, but still I can't seem to get this working. I've checked all my wiring and even connected it to an Arduino and it ran perfectly. So now I'm thinking it has something to do the the ATmega. Do any pins need pull-up or pull-down resistors on them? Or is there maybe something else that is the issue?

enter image description here

One of my codes:

#include <avr/io.h>
#include <util/delay.h>


int main(void)
{
    


DDRB = 0b00000111; // pin 1(data), 2(clock) and 3(latch) are outputs

PORTB = 0b00000000;


//_delay_ms(1);
uint16_t data;
data = 0b0000110000000000; // data to shift out to the register
//read bit
uint16_t mask;
for (mask = 0b1000000000000000; mask>0; mask >>= 1)
{
    
    //iterate through bit mask
    if (data & mask)
    { // if bitwise AND resolves to true
        // send one
        PORTB |= 1 << PINB0;
        //_delay_ms(1);
        // tick
        PORTB |= 1 << PINB1;
        //_delay_ms(1);
        // tock
        PORTB &= ~(1 << PINB1);
        //_delay_ms(1);
    }
    else{ //if bitwise and resolves to false
        // send 0
        PORTB &= ~(1 << PINB0);
        //_delay_ms(1);
        // tick
        PORTB |= 1 << PINB1;
        //_delay_ms(1);
        // tock
        PORTB &= ~(1 << PINB1);
        //_delay_ms(1);
    }
    
    
    
}

PORTB |= 1 << PINB2; // latch all the data
//_delay_ms(1);
PORTB &= ~(1 << PINB2); // latch pin 3 is low
_delay_ms(1000);


}

I'm trying to use an ATmega32 to communicate to a MAX7219 chip for multiplexing with an led matrix. However, I do have multiple different devices that I want to communicate with.

I am trying to communicate with the device without actually using the SPI pins provided on the microcontroller. I have made a test project, but nothing is working. At first it seemed there was something wrong with my code. I've been on other forums and people have shown me better code for doing the job, but still I can't seem to get this working. I've checked all my wiring and even connected it to an Arduino and it ran perfectly. So now I'm thinking it has something to do the the ATmega. Do any pins need pull-up or pull-down resistors on them? Or is there maybe something else that is the issue?

enter image description here

One of my codes:

#include <avr/io.h>
#include <util/delay.h>


int main(void)
{
    


DDRB = 0b00000111; // pin 1(data), 2(clock) and 3(latch) are outputs

PORTB = 0b00000000;


_delay_ms(1);
uint16_t data;
data = 0b0000110000000000; // data to shift out to the register
//read bit
uint16_t mask;
for (mask = 0b1000000000000000; mask>0; mask >>= 1)
{
    
    //iterate through bit mask
    if (data & mask)
    { // if bitwise AND resolves to true
        // send one
        PORTB |= 1 << PINB0;
        _delay_ms(1);
        // tick
        PORTB |= 1 << PINB1;
        _delay_ms(1);
        // tock
        PORTB &= ~(1 << PINB1);
        _delay_ms(1);
    }
    else{ //if bitwise and resolves to false
        // send 0
        PORTB &= ~(1 << PINB0);
        _delay_ms(1);
        // tick
        PORTB |= 1 << PINB1;
        _delay_ms(1);
        // tock
        PORTB &= ~(1 << PINB1);
        _delay_ms(1);
    }
    
    
    
}

PORTB |= 1 << PINB2; // latch all the data
_delay_ms(1);
PORTB &= ~(1 << PINB2); // latch pin 3 is low
_delay_ms(1000);


}
Source Link

communicating to shift register with ATmega32 without using given SPI pins

I'm trying to use an ATmega32 to communicate to a MAX7219 chip for multiplexing with an led matrix. However, I do have multiple different devices that I want to communicate with.

I am trying to communicate with the device without actually using the SPI pins provided on the microcontroller. I have made a test project, but nothing is working. At first it seemed there was something wrong with my code. I've been on other forums and people have shown me better code for doing the job, but still I can't seem to get this working. I've checked all my wiring and even connected it to an Arduino and it ran perfectly. So now I'm thinking it has something to do the the ATmega. Do any pins need pull-up or pull-down resistors on them? Or is there maybe something else that is the issue?

enter image description here

One of my codes:

#include <avr/io.h>
#include <util/delay.h>


int main(void)
{
    


DDRB = 0b00000111; // pin 1(data), 2(clock) and 3(latch) are outputs

PORTB = 0b00000000;


//_delay_ms(1);
uint16_t data;
data = 0b0000110000000000; // data to shift out to the register
//read bit
uint16_t mask;
for (mask = 0b1000000000000000; mask>0; mask >>= 1)
{
    
    //iterate through bit mask
    if (data & mask)
    { // if bitwise AND resolves to true
        // send one
        PORTB |= 1 << PINB0;
        //_delay_ms(1);
        // tick
        PORTB |= 1 << PINB1;
        //_delay_ms(1);
        // tock
        PORTB &= ~(1 << PINB1);
        //_delay_ms(1);
    }
    else{ //if bitwise and resolves to false
        // send 0
        PORTB &= ~(1 << PINB0);
        //_delay_ms(1);
        // tick
        PORTB |= 1 << PINB1;
        //_delay_ms(1);
        // tock
        PORTB &= ~(1 << PINB1);
        //_delay_ms(1);
    }
    
    
    
}

PORTB |= 1 << PINB2; // latch all the data
//_delay_ms(1);
PORTB &= ~(1 << PINB2); // latch pin 3 is low
_delay_ms(1000);


}