Dear;
Please a I have a problem, some help is ok, sorry my bad English.
1 - I need send a byte in oneWire protocol at 115200 bps by I/O port
2 - I can´t to use the CC2540 UART in my project, it is in use.
The problem is after change my code size, the bits temporization change.
1 - I check and use the Tx_Byte routine and bit times is ok .
2 - When I put some C instructions in another code place, some times only this asm("NOP") is necessary to start the problem, my application no work because the Tx_Byte bits temporizations is wrong.
To use a call to Tx_Byte, or duplicate the code in main loop for teste, I have the problem same problem. Tx_Byte is before 0x07000 FLASH memory.
I´m using the CC2540 and 8051 architectural for first time.
All the time I check this:
1- All interrupt is disable.
2- Clock register configuration is OK ( 32Mhz external crystal)
3 - Global interrupt is disabled ( EA = 0 )
4 - The compiler code is OK, no dead code eliminations Ex.: for(){} loops.
I tried to solved the problem in C and Assembler.
void Tx_Byte( uint8_t byte ){
uint8_t dlyus, numBits,mascara;
mascara = 1;
//start Bit
TX_1W_SET = TX_1W_LOW_LEVEL;
for (dlyus = 100; dlyus!= 0; dlyus--) {}
// send 8 bits
for ( numBits = 0; numBits <= 7; numBits++ ) {
//LED_OP_A_SET = 1; //debug
//LED_OP_A_SET = 0; //debug
asm("SJMP $+2");
asm("SJMP $+2");
if ( byte & mascara ) {
for (dlyus = 2; dlyus!= 0; dlyus--) {}
TX_1W_SET = TX_1W_HIGH_LEVEL;
for (dlyus = 44; dlyus!= 0; dlyus--) {}
}
else {
for (dlyus = 10; dlyus!= 0; dlyus--) {}
TX_1W_SET = TX_1W_LOW_LEVEL;
for (dlyus = 98; dlyus!= 0; dlyus--) {}
}
mascara = mascara << 1;
}
//LED_OP_A_SET = 1; //debug
asm("SJMP $+2");
// stop bit
for (dlyus = 10; dlyus!= 0; dlyus--) {}
TX_1W_SET = TX_1W_HIGH_LEVEL;
for (dlyus = 77; dlyus!= 0; dlyus--) {}
//LED_OP_A_SET = 0; //debug 3 Tcycles
}
No optmized code in Assembler for Tx_Byte version:
void Tx_Byte( uint8_t byte ){
// Read input value, compiler transfer uint8 paramenters in this order( R1,R2,R3,R4,R5)
// 8bits
asm("MOV R2,#8");
//LED_OP_A_SET = 0; //todo
//Start Bit
TX_1W_SET = TX_1W_LOW_LEVEL; // Tx bit 0
asm("MOV A,#110");
asm("DEC A");
asm("JNZ $-1");
// get bit
txloop asm("MOV A,R1");
asm("RRC A");
asm("MOV R1,A");
//LED_OP_A_SET = 1; //debug
//LED_OP_A_SET = 0; //debug
asm("SJMP $+2");
asm("SJMP $+2");
asm("JNC txbit0");
// Tx bit1
asm("MOV A,#1");
asm("DEC A");
asm("JNZ $-1");
TX_1W_SET = TX_1W_HIGH_LEVEL; // Tx bit 1
asm("MOV A,#126");
asm("DEC A");
asm("JNZ $-1");
asm("SJMP txchk");
// Tx bit0
txbit0 asm("MOV A,#19");
asm("DEC A");
asm("JNZ $-1");
TX_1W_SET = TX_1W_LOW_LEVEL; // Tx bit 0
asm("MOV A,#54");
asm("DEC A");
asm("JNZ $-1");
asm("SJMP $+2");
// 8 bits ?
txchk asm("MOV A,R2");
asm("DEC A");
asm("MOV R2,A");
asm("JNZ txloop");
if( TX_1W_SET == TX_1W_LOW_LEVEL ){
asm("MOV A,#3");
asm("DEC A");
asm("JNZ $-1");
}
// Stop bit
TX_1W_SET = TX_1W_HIGH_LEVEL; // Tx bit 1
asm("MOV A,#75");
asm("DEC A");
asm("JNZ $-1");
//LED_OP_A_SET = 0; //todo
}