SHARE
TWEET

Untitled

a guest Jul 20th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static uint8_t inbufdata[32];
  2. static uint8_t outbufdata[32];
  3.  
  4. void ss_init(){
  5.  
  6.   // Output
  7.  
  8.   TCCR0A |= (1 << WGM01); // Clear timer0 on compare. This is core to both send and receive.
  9.   OCR0A = ss_clks; // 138 achieves 115200 bps. 238 theoretically gives very nearly 7 overflows for 9600 baud at 16Mhz. 201 with tweak of -8 gives reasonable 9600bps.
  10.   TCCR0B |= (0<<CS02) | (0<<CS01) | (1<<CS00); // 0 0 1 = no clock prescale
  11.   //TIMSK0 |= (1 << OCIE0A); // Set the ISR COMPA vect active. No longer done here as we don't want to waste time firing interrupts unless we're busy.
  12.   DDRC |= (1<<PC0); // Make the pin an output
  13.   PORTC |= (1<<PC0); // Idle high for serial data.
  14.  
  15.   // Input
  16.  
  17.   DDRC &= ~(1<<PC1); // Make the pin an input.
  18.   //PORTC |= (1<<PC1); // Pullup
  19.   PCMSK1 |= (1<<PCINT9); // Enable PC1 pin change interrupt. PC1 is PCINT9, which is in PCMSK group 1.
  20.   PCICR |= (1<<PCIE1); // Enable scan for changes on PCMSK1-relevant pins
  21.  
  22.   // Test pin
  23.  
  24.   DDRC |= (1<<PC2); // Make the pin an output.
  25.   PORTC |= (1<<PC2); // Idle low
  26.  
  27.   // Configure buffers
  28.  
  29.   // Put some predictable numbers in them so we can tell if we're even reading it right
  30.  
  31.   for(uint8_t i = 0; i < 32; i++){
  32.     outbufdata[i] = i;
  33.     inbufdata[i] = i;
  34.   }
  35.  
  36.   // Set up length and buffer area in buffer structs
  37.  
  38.   ss_outbuf.len = SS_OUTPUT_BUFFER_LEN;
  39.   ss_outbuf.data = outbufdata; //(uint8_t *) malloc(ss_outbuf.len);
  40.   ss_inbuf.len = SS_INPUT_BUFFER_LEN;
  41.   ss_inbuf.data = inbufdata; //(uint8_t *) malloc(ss_inbuf.len);
  42.  
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top