I am trying to work with SCI on the uC MC9S12XHY256 and seem to set right baud rate of 9600 and I think my initialization is correct. If i send char ‘A’, 'B' and decimal value 1 is working. I send decimal zero or null char is not working.
Does anyone have an idea?
Hi Daniel,
Thank you for your support.
I want to send sensor value for 4 digits and my requirement is only two bytes.
how to transmit in SCI?
Ex: I send sensor value 3245
Transmit side:
int16 sensor_val = 3245
char buffer[2];
buffer[0]=sensor_val /256
buffer[1]=sensor_val %256
if i send sensor_val = 280
buffer[0]=1
buffer[1]=24
if i send sensor_val =240
buffer[0]=0
buffer[1]=240
Receiver side :
int8 getdata,getdata1;
int16 sensorout;
getdata = buffer[0];
getdata1 = buffer[1];
sensorout = (getdata *256+getdata1 )
sensorout = 3245
Regards
Devaraj
Hi,
Use bit shift:
uint16_t sensor_val = 3245;
uint8_t sensor_val_low, sensor_val_high;
sensor_val_low = (sensor_val & 0xFF);
sensor_val_high = (sensor_val >> 8);
buffer[0]= sensor_val_low;
buffer[1]= sensor_val_high;
And the other way round on the other site.
uint16_t sensorout;
uint8_t getdata_low, getdata_high;
getdata_low = buffer[0];
getdate_high = buffer[1];
sensorout = (getdata_high << 8);
sensorout |= getdata_low;
Regards
Daniel
Hi
If you want to send decimal 0, send 0x30 (ASCII).
arr[1] = 0x30;
PutChar1(arr[1]);
Regards
Daniel
Hi
Could you provide us the code?
Note: In case a resource(s) cannot be publicly shared on Community, use the following procedure.
Regards
Daniel
Hi,
The attached code is what i am using to try to send data out the SCI port.The problem that no response for decimal zero on the output window(hyper terminal). code:
void SCI_Config(uint16 prescaler)
{
SCI1BDH = (uint8)((prescaler>>8));
SCI1BDL = (uint8)(prescaler);
SCI1CR1 = 0x00;
SCI1CR2 = 0x2C;
}
void PutChar1(uint8 ch)
{
while(!SCI1SR1_TDRE) {};
SCI1DRL = ch;
}
void main(void)
{
Clock_Init();
SCI_Config(156);
EnableInterrupts;
arr[0] ='A';
arr[1] = 0;
arr[2] = 'B';
PutChar1(arr[0]);
PutChar1(arr[1]);
PutChar1(arr[2]);
for(;;)
{
}
}
EXample:
Input
arr[0] ='A';
arr[1] = 0;
arr[2] = 'B';
output
A B
Thank you,
Regards,
Devaraj