Author Topic: Atmega Pin to send Data  (Read 1055 times)

0 Members and 1 Guest are viewing this topic.

Offline yalectTopic starter

  • Regular Contributor
  • *
  • Posts: 123
Atmega Pin to send Data
« on: December 26, 2017, 09:09:44 am »
Hi,
I would like to ask you that I want to sand data 8 bits or (1 byte) out of Atmega 32 throw one Pin of Port  like Port b for example which it means serially I found some Ideas like using -and- operation logic to compare the Data with 1 logic and shifting that Data right or left for eight times I made example in C but it did't work.
may you provide me an Idea or simple in C example?
thank you 
« Last Edit: December 26, 2017, 10:11:44 am by yalect »
 

Offline matseng

  • Frequent Contributor
  • **
  • Posts: 563
  • Country: se
    • My Github
Re: Atmega Pin to send Data
« Reply #1 on: December 26, 2017, 10:24:52 am »
For UART or SPI data?  But the correct term for this is "bitbang" or "software serial" or "softserial". So a google for instance  ATMEGA BITBANG SPI should turn up some relevant codes for you to pursue.
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: Atmega Pin to send Data
« Reply #2 on: December 26, 2017, 11:18:21 am »
Perhaps this will help. Didn't test. If I typoed something, sorry.

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  int bits = 12345; // binary 0011 0000 0011 1001

  // use bits to flash built-in LED on a 1-second cycle
  for (int index = 0; index < 16; index++)
  {
    if ((bits >> index) & 1) // shift right, then mask bottom bit
    {
      // if bit was 1, give long flash on LED
      digitalWrite(LED_BUILTIN, HIGH);
      delay(900);
      digitalWrite(LED_BUILTIN, LOW);
      delay(100);
    }
    else
    {
      // if bit was 0, give short flash on LED
      digitalWrite(LED_BUILTIN, HIGH);
      delay(100);
      digitalWrite(LED_BUILTIN, LOW);
      delay(900);
     }
  }
  delay(5000); wait 5 seconds, then repeat.
}
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf