|
|
@ -45,9 +45,8 @@ volatile bool IsSending;
|
|
|
|
/** Software USART raw frame bits for transmission/reception. */
|
|
|
|
/** Software USART raw frame bits for transmission/reception. */
|
|
|
|
volatile uint16_t SoftUSART_Data;
|
|
|
|
volatile uint16_t SoftUSART_Data;
|
|
|
|
|
|
|
|
|
|
|
|
/** Bits remaining to be sent or received via the software USART. */
|
|
|
|
/** Bits remaining to be sent or received via the software USART - set as a GPIOR for speed. */
|
|
|
|
volatile uint8_t SoftUSART_BitCount;
|
|
|
|
#define SoftUSART_BitCount GPIOR2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** ISR to manage the software USART when bit-banged USART mode is selected. */
|
|
|
|
/** ISR to manage the software USART when bit-banged USART mode is selected. */
|
|
|
|
ISR(TIMER1_COMPA_vect, ISR_BLOCK)
|
|
|
|
ISR(TIMER1_COMPA_vect, ISR_BLOCK)
|
|
|
@ -59,21 +58,13 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK)
|
|
|
|
if (!(SoftUSART_BitCount))
|
|
|
|
if (!(SoftUSART_BitCount))
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
/* Check to see if the current clock state is on the rising or falling edge */
|
|
|
|
/* Check to see if we are at a rising or falling edge of the clock */
|
|
|
|
bool IsRisingEdge = (BITBANG_PDICLOCK_PORT & BITBANG_PDICLOCK_MASK);
|
|
|
|
if (BITBANG_PDICLOCK_PORT & BITBANG_PDICLOCK_MASK)
|
|
|
|
|
|
|
|
|
|
|
|
if (IsSending && !IsRisingEdge)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (SoftUSART_Data & 0x01)
|
|
|
|
/* If at rising clock edge and we are in send mode, abort */
|
|
|
|
BITBANG_PDIDATA_PORT |= BITBANG_PDIDATA_MASK;
|
|
|
|
if (IsSending)
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
BITBANG_PDIDATA_PORT &= ~BITBANG_PDIDATA_MASK;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SoftUSART_Data >>= 1;
|
|
|
|
|
|
|
|
SoftUSART_BitCount--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!IsSending && IsRisingEdge)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Wait for the start bit when receiving */
|
|
|
|
/* Wait for the start bit when receiving */
|
|
|
|
if ((SoftUSART_BitCount == BITS_IN_FRAME) && (BITBANG_PDIDATA_PIN & BITBANG_PDIDATA_MASK))
|
|
|
|
if ((SoftUSART_BitCount == BITS_IN_FRAME) && (BITBANG_PDIDATA_PIN & BITBANG_PDIDATA_MASK))
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -84,6 +75,20 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK)
|
|
|
|
SoftUSART_Data >>= 1;
|
|
|
|
SoftUSART_Data >>= 1;
|
|
|
|
SoftUSART_BitCount--;
|
|
|
|
SoftUSART_BitCount--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/* If at falling clock edge and we are in receive mode, abort */
|
|
|
|
|
|
|
|
if (!IsSending)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (SoftUSART_Data & 0x01)
|
|
|
|
|
|
|
|
BITBANG_PDIDATA_PORT |= BITBANG_PDIDATA_MASK;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
BITBANG_PDIDATA_PORT &= ~BITBANG_PDIDATA_MASK;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SoftUSART_Data >>= 1;
|
|
|
|
|
|
|
|
SoftUSART_BitCount--;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
@ -120,7 +125,7 @@ void PDITarget_EnableTargetPDI(void)
|
|
|
|
asm volatile ("NOP"::);
|
|
|
|
asm volatile ("NOP"::);
|
|
|
|
|
|
|
|
|
|
|
|
/* Fire timer compare ISR every 100 cycles to manage the software USART */
|
|
|
|
/* Fire timer compare ISR every 100 cycles to manage the software USART */
|
|
|
|
OCR1A = 100;
|
|
|
|
OCR1A = 80;
|
|
|
|
TCCR1B = (1 << WGM12) | (1 << CS10);
|
|
|
|
TCCR1B = (1 << WGM12) | (1 << CS10);
|
|
|
|
TIMSK1 = (1 << OCIE1A);
|
|
|
|
TIMSK1 = (1 << OCIE1A);
|
|
|
|
|
|
|
|
|
|
|
|