This code doesn't send data through the UART when I connect two Board-DE2 with a COM wire. I don't understand why it isn't operating. What's wrong?
#define RS232_UART_DATA ((volatile int*) 0x10001010)
#define RS232_UART_CONTROL ((volatile int*) (0x10001010+4))
int main()
{
unsigned char hwld[] = {'H','e','l','l','o',' ','W','o','r','l','d','\0'};
unsigned char *pOutput;
pOutput = hwld;
while(*pOutput) //strings in C are zero terminated
{
//if room in output buffer
if((*RS232_UART_CONTROL)&0xffff0000 )
{
//then write the next character
*RS232_UART_DATA = (*pOutput++);
}
}
}
Could you be more specific about "connect two Board-DE2 by Com wire"? Do you want two DE2 Boards to communicate with each other? According to the web link provided by #HansPassant above, you're supposed to connect the DE2 Board to a PC that runs TeraTerm. Try this setup first and make sure you enter the correct COM port settings in TeraTerm as mentioned on the webpage.
Related
I am working with a Zynq board where a custom AXI 4 lite slave peripheral is created and then added from the IP Repository.
And created a synthesizable custom IP in vivado (which is sine wave IP)and also wrote a C code for reading this IP output ( i want to read a data from the register). But somehow it shows something diff. instead of what I expect.
Here I'm attaching a screenshot and my c code for that.
But in teraterm it shows some garbage memory state.
Here, I'm expecting a sinewave output. ( In digit form )
Pls, suggest me correction or suggestion about Where could I have gone wrong or what have I missed in C code?.
#include "xil_printf.h"
#include "xil_io.h"
#include "xparameters.h"
#include "xil_types.h"
#include "xparameters_ps.h"
#include <stdio.h>
//Definitions for peripheral MYIPINETHREE_0 //
#define XPAR_ MYIPINETHREE_0_DEVICE_ID 0
#define XPAR_ MYIPINETHREE_0_S00_AXI_BASEADDR 0x43C00000
#define XPAR_ MYIPINETHREE_0_S00_AXI_HIGHADDR 0x43C0FFFF
int main(){
u32 baseaddr;
int sine, sinephase, enable,reg ;
while (1)
{
xil_printf("start of ip test\r");
if (enable == 1)
reg = 0xFFFFFFFF;
else
reg = 0x00000000;
Xil_Out32(0x43C00000, 32 );
sine = Xil_In32(baseaddr+4);
xil_printf("\r state: %d", sine);
Xil_Out32(0x43C00000, 32);
sinephase = Xil_In32(baseaddr+4);
xil_printf("\r state: %d", sinephase);
return 0;
}
}
To start with: you never initialize baseaddr but use it to read from.
Also I can't say because I have no idea how to verify that your addresses are correct. Normally you should use the defines from your xparameters.h file where the Xilinx board package program puts them. I don't see that happening here.
I am somewhat suspicious as all my Xilinx AXI addresses start with 0x800... but then I might be because I am using a different FPGA.
Please add a board layout or some additional information. You should use the addresses from xparameters.hinstead of hard coding them into your source code. The address space depends on your AXI master interface.
Using Atmel studio 7, with STK600 and 32UC3C MCU
I'm pulling my hair over this.
I'm sending strings of a variable size over UART once every 5 seconds. The String consists of one letter as opcode, then two chars are following that tell the lenght of the following datastring (without the zero, there is never a zero at the end of any of those strings). In most cases the string will be 3 chars in size, because it has no data ("p00").
After investigation I found out that what supposed to be "p00" was in fact "0p0" or "00p" or (only at first try after restarting the micro "p00"). I looked it up in the memory view of the debugger. Then I started hTerm and confirmed that the data was in fact "p00". So after a while hTerm showed me "p00p00p00p00p00p00p00..." while the memory of my circular uart buffer reads "p000p000p0p000p0p000p0p0..."
edit: Actually "0p0" and "00p" are alternating.
The baud rate is 9600. In the past I was only sending single letters. So everything was running well.
This is the code of the Receiver Interrupt:
I tried different variations in code that were all doing the same in a different way. But all of them showed the exact same behavior.
lastWebCMDWritePtr is a uint8_t* type and so is lastWebCMDRingstartPtr.
lastWebCMDRingRXLen is a uint8_t type.
__attribute__((__interrupt__))
void UartISR_forWebserver()
{
*(lastWebCMDWritePtr++) = (uint8_t)((&AVR32_USART0)->rhr & 0x1ff);
lastWebCMDRingRXLen++;
if(lastWebCMDWritePtr - lastWebCMDRingstartPtr > lastWebCMDRingBufferSIZE)
{
lastWebCMDWritePtr = lastWebCMDRingstartPtr;
}
// Variation 2:
// advanceFifo((uint8_t)((&AVR32_USART0)->rhr & 0x1ff));
// Variation 3:
// if(usart_read_char(&AVR32_USART0, getReadPointer()) == USART_RX_ERROR)
// {
// usart_reset_status(&AVR32_USART0);
// }
//
};
I welcome any of your ideas and advices.
Regarts Someo
P.S. I put the Atmel studio tag in case this has something to do with the myriad of debugger bugs of AS.
For a complete picture you would have to show where and how lastWebCMDWritePtr, lastWebCMDRingRXLen, lastWebCMDRingstartPtr and lastWebCMDRingBufferSIZE are used elsewhere (on the consuming side)
Also I would first try a simpler ISR with no dependencies to other software modules to exclude a hardware resp. register handling problem.
Approach:
#define USART_DEBUG
#define DEBUG_BUF_SIZE 30
__attribute__((__interrupt__))
void UartISR_forWebserver()
{
uint8_t rec_byte;
#ifdef USART_DEBUG
static volatile uint8_t usart_debug_buf[DEBUG_BUF_SIZE]; //circular buffer for debugging
static volatile int usart_debug_buf_index = 0;
#endif
rec_byte = (uint8_t)((&AVR32_USART0)->rhr & 0x1ff);
#ifdef USART_DEBUG
usart_debug_buf_index = usart_debug_buf_index % DEBUG_BUF_SIZE;
usart_debug_buf[usart_debug_buf_index] = rec_byte;
usart_debug_buf_index++
if (!(usart_debug_buf_index < DEBUG_BUF_SIZE)) {
usart_debug_buf_index = 0; //candidate for a breakpoint to see what happened in the past
}
#endif
//uart_recfifo_enqueue(rec_byte);
};
I'm trying to build a raw data with ethernet frame via C code.
I built a packet (included Ethernet->IP->UDP->DHCP protocols) and sent it via the WiFi interface. I followed it via the Wireshark which prints out:
Ethernet2 -> Frame Check Sequence -> Incorrect, should be XXX.
I did not build an FCS data in my packet, I left the field blank.
Now, I can't find any simple function/code in C which does that. All the codes I found gave me a bad output.
Someone done it before and can share how to implement the FCS in the Ethernet packet?
Thank you in advance
FIX: it seems that FCS calculation is only optional, I added the IP checksum calculation instead and that was enough for the DHCP to pass.
Thanks.
try:
#define BYTE unsigned char
int fcs(BYTE* paquete,int n){
int byte,sum=0;
n++;
for(int j=0;j<=n;j++){
byte=paquete[j];
for(int i=0;i<8;i++){
if(j!=n && i<7){
sum = sum+(byte & 0x01);
byte = byte >> 1;
}
}
}
return sum;
}
I have a problem when I receive data from the eeprom.
first I made the following code :
#include <avr/io.h>
#include <avr/eeprom.h>
char NAME[5] EEMEM = "a001";
char UNIT[2] EEMEM = "C";
uint16_t CYCLICITY EEMEM = 2000;
int main(void)
{
while(1)
{
//TODO:: Please write your application code
}
}
and from this I have extracted a .hex and .eep files. Then I wrote this files with avrdude. First I write this wrong because I put only the .hex file on eerpom:w and I destroy some bytes, this is not so important. After that I write using the correct command and I see part of the data like in the next print screen.
I am saving a number , a C and a001 . As you see in the first row there is ..C.a001. which are the 9 bytes I wrote.
now in another program! I try to do this:
char EEMEM NAME[5] ;
char EEMEM UNIT[2] ;
uint16_t EEMEM CYCLICITY;
void _vReadEEPROM(char *au8Name,char *au8Unit,uint16_t *u16Cyclicity)
{
eeprom_read_block((void *)&au8Name,(const void *)NAME,5);
eeprom_read_block((void *)&au8Unit,(const void *)UNIT,2);
*u16Cyclicity = eeprom_read_word(&CYCLICITY);
}
The parametres are in a global struct :
typedef struct
{
uint16_t u16Cyclicity;
uint16_t u16Value;
char pu8Name[5];
char pu8Unit[2];
}EEH_layout;
In the while of the main I sent on the "Broken UART"(I have another topic on that). Until this code the USART sent the good value and garbage..but when I put this the USART is not sending anything, and as I beleive this is cause because of a 0(null) reading from eeprom.
The CPU is working because I have a 1 sec timer that interupts to blink a led. THis is working, so the probelm is that I got 0 from EEPORM.
ALSO I AM NOT SURE I UDERSTAND HOW TO WRITE THE EEPROM BECAUSE EVERYWHERE ARE A LOT OF TUTORIALS ON EEPROM BUT NOWHERE IS TELLING HOW TO CONFIG EEPROM AND ONLY READ. I do not want to have this params in my code, I want them from eeprom that I will write alone!
EDIT: the uint16 parameter is ok, I manage to read it over UART and it is 2000; But the chars are not ok, it is null.
EDIT:
TEST OK, the problem was that the params of function was not use ok. I change the function with pau8Name[] instead of *pau8Name, because the pointer wAS bad initialized!!
Always be aware of pointers!
The problem was with the uninitialized pointer. See EDIT in post!
I'm adapting a sketch I found to send sensor data over a wifi chip (Nrf2401), and although I get the message through, the value I send contains decimals (e.g. 24.59), but the received message will only be 24.
I'm sure there's something wrong on the transmitter part of the code, but I can't see what.
Here's my code:
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(4);
DallasTemperature sensors(&oneWire);
// ce,csn pins
RF24 radio(8,7);
unsigned char data[3] = {
0};
unsigned long count=0;
void setup(void)
{
sensors.begin();
Serial.begin(57600);
Serial.println("**************V1 Send Sensor Data***********");
radio.begin();
radio.setPALevel(RF24_PA_LOW);
radio.setChannel(0x4c);
// open pipe for writing
radio.openWritingPipe(0xF0F0F0F0E1LL);
radio.enableDynamicPayloads();
radio.setAutoAck(true);
radio.powerUp();
Serial.println("...Sending");
}
void loop(void)
{
sensors.requestTemperatures();
float currentTemp;
currentTemp = sensors.getTempCByIndex(0);
//assign 'T' to represent a Temperature reading
data[0] = 'T';
data[1] = currentTemp;
count++;
// print and increment the counter
radio.write(data, sizeof(float)+1);
Serial.print("Temperature sent: ");
Serial.println(currentTemp);
// pause a second
delay(500);
}
In this example, when I print currentTemp, it will display the decimals, but if I print data[1], it won't.
What am I missing?
You are assigning data [1] = currentTemp. Current temp is a float, not a character so this won't work. Decimals are lost because the float will be cast to a char in the assignment. Make data into a larger buffer and use sprintf to print currentTemp if you want to use it as a string. Really you should be writing just currentTemp to the radio and formatting on the other end, which will make the operation faster and require less bandwith to transmit (not to mention that transmitting and formatting are different concerns and should be separated, not coupled, when possible).