Porting Atmel C to PASM ...
MacTuxLin
Posts: 821
Hello All,
After getting this chip (AT88SA102S) & mounted it on my board, I realised I had problems with this chip despite thoroughly reading the datasheet, which I later found it had missed out an important sleep_to_wake time that I discovered in the source code. But still, does not seems to solve the problem. Basically, I'm trying to get a response from the chip to ensure my timing are OK but it just did not initiate a t_start.
To access this chip, I need to send a Wake Token, followed by a Transmit Flag with a sleep_to_wake time in between & I ought to get a $11 in return. Please excuse the mess as they are still work-in-progress. I must have err somewhere.
As always, thanks a lot.
I'm trying to port the same flow as these shown over to PASM (full source attached)
After getting this chip (AT88SA102S) & mounted it on my board, I realised I had problems with this chip despite thoroughly reading the datasheet, which I later found it had missed out an important sleep_to_wake time that I discovered in the source code. But still, does not seems to solve the problem. Basically, I'm trying to get a response from the chip to ensure my timing are OK but it just did not initiate a t_start.
To access this chip, I need to send a Wake Token, followed by a Transmit Flag with a sleep_to_wake time in between & I ought to get a $11 in return. Please excuse the mess as they are still work-in-progress. I must have err somewhere.
As always, thanks a lot.
'------------------------------------------------------------------------------
' ### AT88SA102S ### - (New 29 May 2012)
' input: declared inside
' output: 1 byte, suppose to reply from Wake Token signal
'------------------------------------------------------------------------------
_at_newWaketoken mov bitCnt, #8 ' read an 8-bit byte
'Set pin as output
mov dira, dataMask
mov value, #$F0 ' Set value
mov cnt, cnt
add cnt, #9
'-----------------------------------------------------------------------
'Send Wake Signal
'-----------------------------------------------------------------------
:_at_sendWakeAgain waitcnt cnt, write_t_szhilo
or dira, dataMask 'Low
waitcnt cnt, write_t_szhilo
andn dira, dataMask 'High
shr value, #1 wc
waitcnt cnt, write_t_szhilo
muxnc dira, dataMask ' low/high
waitcnt cnt, write_high_short
andn dira,dataMask ' low/high
djnz bitCnt, #:_at_sendWakeAgain
'* Sleep-Wake Delay (30 May 2012), found this in Atmel's code for AT88SA102S
waitcnt cnt, sleepWake_Delay
'-----------------------------------------------------------------------
'Send Transmit Flag
'-----------------------------------------------------------------------
mov value, #$88
mov bitCnt, #8
:_at_newTransmit waitcnt cnt, write_t_szhilo
or dira, dataMask 'Low
waitcnt cnt, write_t_szhilo
andn dira, dataMask 'High
shr value, #1 wc
waitcnt cnt, write_t_szhilo
muxnc dira, dataMask ' low/high
waitcnt cnt, write_high_short
andn dira,dataMask ' low/high
djnz bitCnt, #:_at_newTransmit
waitcnt cnt, #0
'Set pin as input
andn dira, dataMask
'-----------------------------------------------------------------------
'Read byte from AT88SA
'-----------------------------------------------------------------------
mov bitCnt, #8 ' read an 8-bit byte
mov shiftCnt, #32 ' get shift count
sub shiftCnt, bitCnt
mov cnt, cnt
add cnt, #9
:_at_newReadBlock waitcnt cnt, readByte_LH 'readByte_HighLong
:_at_newReadBitLow test dataMask, ina wz ' Should be Low
if_nz jmp #:_at_newReadBitLow ' Waiting for start signal (low) from IC <--- !!!! STUCK HERE !!!!
add cnt, readByte_LH
:_at_newReadBitHigh test dataMask, ina wc
if_nc jmp #:_at_newReadBitHigh
add cnt, readByte_LH
test dataMask, ina wz
ror value, #1
waitcnt cnt, readByte_HighLong
'Check to make sure it is High
:_at_newReadMakeSure test dataMask, ina wc
if_nc jmp #:_at_newReadMakeSure
djnz bitCnt, #:_at_newReadBlock
shr value, shiftCnt
'Reset pin as output
mov dira, dataMask ' Bring up again
_at_newWaketoken_ret
_at_new_ret ret
'-------------------- constant values -----------------------------------------
wake_whi long 12_000 '3.2ms, Min is 2.5ms but since _delay is multiple of 4 so use 3.2ms
t_timeout long 40_000 'Min is 45 msec
'--- New --- (29 May 2012)
wake_low long 6_400 'Try 80 usec, min is 60 usec in datasheet
wake_high long 200_000 'Try 2.5 msec, min is 2.5msec in datasheet
write_t_szhilo long 347 '4.34 usec (t_start, t_zhi, t_zlo) all shares the same value.
write_high_long long 2_425 't_bit - t_start - t_zhi = 30.32 usec
write_high_short long 2_079 't_bit - t_start - t_zhi - t_zlo = 25.98 usec
readByte_LH long 480 'Both Low & High is 6 usec (typ value), min 4.6 usec, max 8.6 usec
readByte_HighLong long 2_880 '36us ,Read from 102s remaining time after last low in logic 0
sleepWake_Delay long 135_040 '2_000 usec - 8-bytes * 39 usec = 1_688 usec = 135_040 ticks
I'm trying to port the same flow as these shown over to PASM (full source attached)
//##########################################################################
// Setup the communication timer
//
TCCR1B &= ~(_BV(CS12) | _BV(CS10)); // clock source disabled
// Clear the counter registers
//
TCNT1 = 0;
// Clock source enabled. We use a pre-scaler value of 64
//
TCCR1B |= (_BV(WGM12) | _BV(CS11) | _BV(CS10));
// Clear the timer compare flag.
//
TIFR1 |= (1 << OCF1A);
// Set the timer to time the entire packet process
// (Wake+WakeDelay+Transmit+Command+MacOut+ExecutionDelay+Transmit+TurnaroundDelay+Transmit+DigestOut)
//
OCR1A = MAX_MAC_TIME;
//##########################################################################
// Send the wake token
//
SendByte(WAKE_TOKEN);
//##########################################################################
// Mandatory sleep->wake delay (not in spec)
//
while (TCNT1 < SLEEP_TO_WAKE_TIME)
;
//##########################################################################
// Send transmit flag
//
SendByte(FLAG_CLIENT_TRANSMIT);
//##########################################################################
// Get the wakup "SYNC" packet
//
if (!ReceivePacket())
{
//#######################################################################
// Send the command flag + command payload + transmit
//
for (index = 0; index < sizeof(cmd_MAC); index++)
SendByte(cmd_MAC[index]);
//#######################################################################
// Wait tExec, send transmit flag
//
while (TCNT1 < MAC_COMMAND_TEXEC_WAIT)
;
SendByte(FLAG_CLIENT_TRANSMIT);
//#######################################################################
// We can now wait here until the chip responds or the overall timer
// fires.
//
returnVal = ReceivePacket();
}
//##########################################################################
// Send Sleep flag
//
SendByte(FLAG_SLEEP);
return returnVal;


Comments