News:

;) This forum is the property of Proton software developers

Main Menu

Changing the byte send sequence

Started by TimB, Feb 11, 2023, 10:00 AM

Previous topic - Next topic

TimB


Hi all

I'm trying to simplify some i2C code from using Bstart, Busout, Ack etc to just i2cout

My issue is that i2cout sends High bytes first then low bytes. But the Slave code sticks it in an array using indexing so data is stored sequentially as I do not know how many bytes will be sent. Just inc index and stick it in an array.

I could add code to unscramble it when needed but just checking first if there is some magical command I do not know about that will reverse the send sequence.

Cheers

Tim

TimB


Actually just writing a couple of conversion subs took less time than it took to write the post

 :-[

John Drew


John Lawton

Would the SWAP command be of any use, I assume it works with arrays and aliased variables?

TimB

Quote from: John Drew on Feb 12, 2023, 08:41 AMDidn't hbusout work Tim?
John

Hbus is using the hardware i2c routines but I need to use the software Bstart etc or i2cout/i2cin

The issue is that Positron sends data High byte first but I save in the array going up eg ai2cM_TO_S_REGS[bi2cM_TO_S_REG_INDEX] = SSPBUF the inc the index so its laying it down in memory as Highbyte first.

Normally Positron list variables low byte first so you cannot simply alias a variable to the array

In the end it was just a simple proc needed to make a copy and swap it back into another variable

Proc SaveNCToi2cBuff()
    InterruptsOff
    ai2cS_TO_M_REGS[0] = bSystemReg

    ai2cS_TO_M_REGS[1] = fBubbleTotal.byte3
    ai2cS_TO_M_REGS[2] = fBubbleTotal.byte2
    ai2cS_TO_M_REGS[3] = fBubbleTotal.byte1
    ai2cS_TO_M_REGS[4] = fBubbleTotal.byte0

    ai2cS_TO_M_REGS[5] = fBubbleVolumeml1hz.byte3
    ai2cS_TO_M_REGS[6] = fBubbleVolumeml1hz.byte2
    ai2cS_TO_M_REGS[7] = fBubbleVolumeml1hz.byte1
    ai2cS_TO_M_REGS[8] = fBubbleVolumeml1hz.byte0

    ai2cS_TO_M_REGS[9] = fCurrentVelocitymms.byte3
    ai2cS_TO_M_REGS[10] = fCurrentVelocitymms.byte2
    ai2cS_TO_M_REGS[11] = fCurrentVelocitymms.byte1
    ai2cS_TO_M_REGS[12] = fCurrentVelocitymms.byte0

    InterruptsOn
EndProc


John Swap is a copy command not a byte,word,dword  inversion

Thanks all

Tim

John Drew

All good Tim, I thought that might be the case.
Pins permitting I always use hardware (if necessary setting registers) as once the byte is loaded into the buffer after checking it's empty, it all happens in the background so less speed impact on other code.
Cheers
John

TimB


Hi John

Unless I implement a i2c interrupt driven buffer there is no advantage in speed using i2cout than Hbus. Since I try and keep the amount of data requested to a minimum so it has little impact.

I do agree that it can if you have a lot of data > than say 8 bytes it does have an impact.

This line     i2cin SDA_Pin, SCL_Pin, SLAVE_ADDR, [bStatus, fFloatin1, fFloatin2, fFloatin3]

Which sends 1 byte (address) and RX's 13 bytes takes ~340us

But farming out some heavy duty code requirements to a separate pic and using i2c to just collect the data every 1hz means the overall CPU load is greatly reduced.

I may put the i2c lines on the hbus pins so I can implement an interrupt driven i2c control system later. Although I still will need 1 software i2c as a device I have, I need 2 off and they clash with the same address.